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 **************************************************************************/
17 //---------------------------------------------------------------------
18 // FastJet v2.3.4 finder algorithm interface
19 // Last modification: Neutral cell energy included in the jet reconstruction
21 // Authors: Rafael.Diaz.Valdes@cern.ch
22 // Magali.estienne@subatech.in2p3.fr (neutral part + bg subtraction option)
24 //---------------------------------------------------------------------
27 #include <Riostream.h>
28 #include <TLorentzVector.h>
33 #include <TClonesArray.h>
35 #include "AliFastJetFinder.h"
36 #include "AliFastJetHeaderV1.h"
37 #include "AliJetReaderHeader.h"
38 #include "AliJetReader.h"
39 #include "AliJetUnitArray.h"
40 #include "AliFastJetInput.h"
41 #include "AliJetBkg.h"
42 #include "AliAODJetEventBackground.h"
43 #include "AliAODTrack.h"
45 #include "fastjet/PseudoJet.hh"
46 #include "fastjet/ClusterSequenceArea.hh"
47 #include "fastjet/AreaDefinition.hh"
48 #include "fastjet/JetDefinition.hh"
49 // get info on how fastjet was configured
50 #include "fastjet/config.h"
52 #ifdef ENABLE_PLUGIN_SISCONE
53 #include "fastjet/SISConePlugin.hh"
56 #include<sstream> // needed for internal io
63 ClassImp(AliFastJetFinder)
66 //____________________________________________________________________________
68 AliFastJetFinder::AliFastJetFinder():
70 fInputFJ(new AliFastJetInput()),
71 fJetBkg(new AliJetBkg())
76 //____________________________________________________________________________
78 AliFastJetFinder::~AliFastJetFinder()
81 delete fInputFJ; fInputFJ = 0;
82 delete fJetBkg; fJetBkg = 0;
85 //______________________________________________________________________________
86 void AliFastJetFinder::FindJets()
88 cout<<"----------in AliFastJetFinder::FindJets() ------------------"<<endl;
89 //pick up fastjet header
90 AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
91 Bool_t debug = header->GetDebug(); // debug option
92 Bool_t bgMode = header->GetBGMode(); // choose to subtract BG or not
94 // check if we are reading AOD jets
96 Bool_t fromAod = !strcmp(fReader->ClassName(),"AliJetAODReader");
97 if (fromAod) { refs = fReader->GetReferences(); }
100 // read input particles -----------------------------
102 vector<fastjet::PseudoJet> inputParticles=fInputFJ->GetInputParticles();
103 if(inputParticles.size()==0){
104 Printf("%s:%d No input particles found, skipping event",(char*)__FILE__,__LINE__);
108 // create an object that represents your choice of jet algorithm, and
109 // the associated parameters
110 double rParam = header->GetRparam();
111 fastjet::Strategy strategy = header->GetStrategy();
112 fastjet::RecombinationScheme recombScheme = header->GetRecombScheme();
113 fastjet::JetAlgorithm algorithm = header->GetAlgorithm();
114 fastjet::JetDefinition jetDef(algorithm, rParam, recombScheme, strategy);
116 // create an object that specifies how we to define the area
117 fastjet::AreaDefinition areaDef;
118 double ghostEtamax = header->GetGhostEtaMax();
119 double ghostArea = header->GetGhostArea();
120 int activeAreaRepeats = header->GetActiveAreaRepeats();
122 // now create the object that holds info about ghosts
123 fastjet::GhostedAreaSpec ghostSpec(ghostEtamax, activeAreaRepeats, ghostArea);
124 // and from that get an area definition
125 fastjet::AreaType areaType = header->GetAreaType();
126 areaDef = fastjet::AreaDefinition(areaType,ghostSpec);
132 if(bgMode) // BG subtraction!!!!!!!!!! Not entering here
134 //***************************** JETS FINDING AND EXTRACTION
135 // run the jet clustering with the above jet definition
136 fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef, areaDef);
138 // save a comment in the header
140 TString comment = "Running FastJet algorithm with the following setup. ";
141 comment+= "Jet definition: ";
142 comment+= TString(jetDef.description());
143 comment+= ". Area definition: ";
144 comment+= TString(areaDef.description());
145 comment+= ". Strategy adopted by FastJet: ";
146 comment+= TString(clust_seq.strategy_string());
147 header->SetComment(comment);
149 cout << "--------------------------------------------------------" << endl;
150 cout << comment << endl;
151 cout << "--------------------------------------------------------" << endl;
153 //header->PrintParameters();
156 // extract the inclusive jets with pt > ptmin, sorted by pt
157 double ptmin = header->GetPtMin();
158 vector<fastjet::PseudoJet> inclusiveJets = clust_seq.inclusive_jets(ptmin);
160 //cout << "Number of unclustered particles: " << clust_seq.unclustered_particles().size() << endl;
163 //subtract background // ===========================================
164 // set the rapididty , phi range within which to study the background
165 double rapMax = header->GetRapMax();
166 double rapMin = header->GetRapMin();
167 double phiMax = header->GetPhiMax();
168 double phiMin = header->GetPhiMin();
169 fastjet::RangeDefinition range(rapMin, rapMax, phiMin, phiMax);
171 // subtract background
172 vector<fastjet::PseudoJet> subJets = clust_seq.subtracted_jets(range,ptmin);
175 //cout << "Printing inclusive sub jets with pt > "<< ptmin<<" GeV\n";
176 //cout << "---------------------------------------\n";
178 //printf(" ijet rap phi Pt area +- err\n");
180 // sort jets into increasing pt
181 vector<fastjet::PseudoJet> jets = sorted_by_pt(subJets);
182 for (size_t j = 0; j < jets.size(); j++) { // loop for jets
184 double area = clust_seq.area(jets[j]);
185 double areaError = clust_seq.area_error(jets[j]);
187 if(debug) printf("Jet found %5d %9.5f %8.5f %10.3f %8.3f +- %6.3f\n", (Int_t)j,jets[j].rap(),jets[j].phi(),jets[j].perp(), area, areaError);
189 // go to write AOD info
190 AliAODJet aodjet (jets[j].px(), jets[j].py(), jets[j].pz(), jets[j].E());
191 //cout << "Printing jet " << endl;
192 if(debug) aodjet.Print("");
193 //cout << "Adding jet ... " ;
195 //cout << "added \n" << endl;
205 else { // No BG subtraction!!!!!!!! Default header is bgmode=0.
207 TClonesArray* fUnit = fReader->GetUnitArray(); //Big mmentum array
208 if(fUnit == 0) { cout << "Could not get the momentum array" << endl; return; }
209 Int_t nIn = fUnit->GetEntries();
212 //fastjet::ClusterSequence clust_seq(inputParticles, jetDef);
213 fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef, areaDef);
215 // save a comment in the header
217 TString comment = "Running FastJet algorithm with the following setup. ";
218 comment+= "Jet definition: ";
219 comment+= TString(jetDef.description());
220 comment+= ". Strategy adopted by FastJet: ";
221 comment+= TString(clust_seq.strategy_string());
222 header->SetComment(comment);
224 cout << "--------------------------------------------------------" << endl;
225 cout << comment << endl;
226 cout << "--------------------------------------------------------" << endl;
228 //header->PrintParameters();
230 // extract the inclusive jets with pt > ptmin, sorted by pt
231 double ptmin = header->GetPtMin();
232 vector<fastjet::PseudoJet> inclusiveJets = clust_seq.inclusive_jets(ptmin);
234 //cout << "Number of unclustered particles: " << clust_seq.unclustered_particles().size() << endl;
236 vector<fastjet::PseudoJet> jets = sorted_by_pt(inclusiveJets); // Added by me
237 for (size_t j = 0; j < jets.size(); j++) { // loop for jets // Added by me
239 if(debug) printf("Jet found %5d %9.5f %8.5f %10.3f \n",(Int_t)j,jets[j].rap(),jets[j].phi(),jets[j].perp());
241 vector<fastjet::PseudoJet> constituents = clust_seq.constituents(jets[j]);
242 int nCon= constituents.size();
244 Double_t area=clust_seq.area(jets[j]);
245 // go to write AOD info
246 AliAODJet aodjet (jets[j].px(), jets[j].py(), jets[j].pz(), jets[j].E());
247 aodjet.SetEffArea(area,0);
248 //cout << "Printing jet " << endl;
249 if(debug) aodjet.Print("");
251 for (int i=0; i < nCon; i++)
253 fastjet::PseudoJet mPart=constituents[i];
254 ind[i]=mPart.user_index();
255 // cout<<i<<" index="<<ind[i]<<endl;
257 //internal loop over all the unit cells
260 for(Int_t ii=0; ii<nIn; ii++)
262 AliJetUnitArray *uArray = (AliJetUnitArray*)fUnit->At(ii);
263 if(uArray->GetUnitEnergy()>0.){
264 uArray->SetUnitTrackID(ipart);//used to have the index available in AliJEtBkg
266 TRefArray* trackArray = (TRefArray*)uArray->GetUnitTrackRef();
267 Int_t tracksInCell = trackArray->GetEntries();
268 for(int j=0;j<tracksInCell;j++){
269 AliAODTrack * track = (AliAODTrack*)trackArray->At(j);
270 aodjet.AddTrack(track);
284 } // end loop for jets
289 //____________________________________________________________________________
290 void AliFastJetFinder::RunTest(const char* datafile)
294 // This simple test run the kt algorithm for an ascii file testdata.dat
295 // read input particles -----------------------------
296 vector<fastjet::PseudoJet> inputParticles;
300 // we assume a file basic.dat in the current directory
301 // this file has 3 columns of float data
304 in >> px >> py >> pz >> en;
305 if (!in.good()) break;
306 //printf("px=%8f, py=%8f, pz=%8fn",px,py,pz);
308 inputParticles.push_back(fastjet::PseudoJet(px,py,pz,en));
310 //printf(" found %d pointsn",nlines);
312 //////////////////////////////////////////////////
314 // create an object that represents your choice of jet algorithm, and
315 // the associated parameters
317 fastjet::Strategy strategy = fastjet::Best;
318 fastjet::RecombinationScheme recombScheme = fastjet::BIpt_scheme;
319 fastjet::JetDefinition jetDef(fastjet::kt_algorithm, rParam, recombScheme, strategy);
323 // create an object that specifies how we to define the area
324 fastjet::AreaDefinition areaDef;
325 double ghostEtamax = 7.0;
326 double ghostArea = 0.05;
327 int activeAreaRepeats = 1;
330 // now create the object that holds info about ghosts
331 fastjet::GhostedAreaSpec ghostSpec(ghostEtamax, activeAreaRepeats, ghostArea);
332 // and from that get an area definition
333 areaDef = fastjet::AreaDefinition(fastjet::active_area,ghostSpec);
336 // run the jet clustering with the above jet definition
337 fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef, areaDef);
340 // tell the user what was done
341 cout << "--------------------------------------------------------" << endl;
342 cout << "Jet definition was: " << jetDef.description() << endl;
343 cout << "Area definition was: " << areaDef.description() << endl;
344 cout << "Strategy adopted by FastJet was "<< clust_seq.strategy_string()<<endl<<endl;
345 cout << "--------------------------------------------------------" << endl;
348 // extract the inclusive jets with pt > 5 GeV, sorted by pt
350 vector<fastjet::PseudoJet> inclusiveJets = clust_seq.inclusive_jets(ptmin);
352 cout << "Number of unclustered particles: " << clust_seq.unclustered_particles().size() << endl;
355 //subtract background // ===========================================
356 // set the rapididty range within which to study the background
357 double rapMax = ghostEtamax - rParam;
358 fastjet::RangeDefinition range(rapMax);
359 // subtract background
360 vector<fastjet::PseudoJet> subJets = clust_seq.subtracted_jets(range,ptmin);
362 // print them out //================================================
363 cout << "Printing inclusive jets after background subtraction \n";
364 cout << "------------------------------------------------------\n";
365 // sort jets into increasing pt
366 vector<fastjet::PseudoJet> jets = sorted_by_pt(subJets);
368 printf(" ijet rap phi Pt area +- err\n");
369 for (size_t j = 0; j < jets.size(); j++) {
371 double area = clust_seq.area(jets[j]);
372 double areaError = clust_seq.area_error(jets[j]);
374 printf("%5d %9.5f %8.5f %10.3f %8.3f +- %6.3f\n",(Int_t)j,jets[j].rap(),
375 jets[j].phi(),jets[j].perp(), area, areaError);
378 // ================================================================
384 //____________________________________________________________________________
386 void AliFastJetFinder::WriteJHeaderToFile()
391 //____________________________________________________________________________
393 Float_t AliFastJetFinder::EtaToTheta(Float_t arg)
395 // return (180./TMath::Pi())*2.*atan(exp(-arg));
396 return 2.*atan(exp(-arg));
401 //____________________________________________________________________________
403 void AliFastJetFinder::InitTask(TChain *tree)
406 printf("Fast jet finder initialization ******************");
407 fReader->CreateTasks(tree);
412 Bool_t AliFastJetFinder::ProcessEvent()
416 // from meomntum array
418 Bool_t ok = fReader->FillMomentumArray();
420 if (!ok) return kFALSE;
421 fInputFJ->SetHeader(fHeader);
422 fInputFJ->SetReader(fReader);
423 fInputFJ->FillInput();
427 fJetBkg->SetHeader(fHeader);
428 fJetBkg->SetReader(fReader);
430 fJetBkg->SetFastJetInput(fInputFJ);
431 Double_t bkg1=fJetBkg->BkgFastJet();
432 Double_t bkg2=fJetBkg->BkgChargedFastJet();
433 Double_t bkg3=fJetBkg->BkgFastJetCone(fAODjets);
434 Double_t bkg4=fJetBkg->BkgRemoveJetLeading(fAODjets);
436 fAODEvBkg->SetBackground(0,bkg1);
437 fAODEvBkg->SetBackground(1,bkg2);
438 fAODEvBkg->SetBackground(2,bkg3);
439 fAODEvBkg->SetBackground(3,bkg4);
446 Bool_t AliFastJetFinder::ProcessEvent2()
450 // Charged only or charged+neutral jets
453 TRefArray* ref = new TRefArray();
454 Bool_t procid = kFALSE;
455 Bool_t ok = fReader->ExecTasks(procid,ref);
457 // Delete reference pointer
458 if (!ok) {delete ref; return kFALSE;}
461 fInputFJ->SetHeader(fHeader);
462 fInputFJ->SetReader(fReader);
463 fInputFJ->FillInput();
468 fJetBkg->SetHeader(fHeader);
469 fJetBkg->SetReader(fReader);
470 fJetBkg->SetFastJetInput(fInputFJ);
471 Double_t bkg1=fJetBkg->BkgFastJet();
472 Double_t bkg2=fJetBkg->BkgChargedFastJet();
473 Double_t bkg3=fJetBkg->BkgFastJetCone(fAODjets);
474 Double_t bkg4=fJetBkg->BkgRemoveJetLeading(fAODjets);
476 fAODEvBkg->SetBackground(0,bkg1);
477 fAODEvBkg->SetBackground(1,bkg2);
478 fAODEvBkg->SetBackground(2,bkg3);
479 fAODEvBkg->SetBackground(3,bkg4);
481 Int_t nEntRef = ref->GetEntries();
483 for(Int_t i=0; i<nEntRef; i++)
485 // Reset the UnitArray content which were referenced
486 ((AliJetUnitArray*)ref->At(i))->SetUnitTrackID(0);
487 ((AliJetUnitArray*)ref->At(i))->SetUnitEnergy(0.);
488 ((AliJetUnitArray*)ref->At(i))->SetUnitCutFlag(kPtSmaller);
489 ((AliJetUnitArray*)ref->At(i))->SetUnitCutFlag2(kPtSmaller);
490 ((AliJetUnitArray*)ref->At(i))->SetUnitSignalFlag(kBad);
491 ((AliJetUnitArray*)ref->At(i))->SetUnitSignalFlagC(kTRUE,kBad);
492 ((AliJetUnitArray*)ref->At(i))->SetUnitDetectorFlag(kTpc);
493 ((AliJetUnitArray*)ref->At(i))->SetUnitFlag(kOutJet);
494 ((AliJetUnitArray*)ref->At(i))->ClearUnitTrackRef();
497 AliJetUnitArray* uA = (AliJetUnitArray*)ref->At(i);
498 uA->ResetBit(kIsReferenced);
502 // Delete the reference pointer