]> git.uio.no Git - u/mrichter/AliRoot.git/blame - JETAN/AliFastJetFinder.cxx
In reconstruction:
[u/mrichter/AliRoot.git] / JETAN / AliFastJetFinder.cxx
CommitLineData
a17e6965 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
392c9b47 16
a17e6965 17//---------------------------------------------------------------------
392c9b47 18// FastJet v2.3.4 finder algorithm interface
8838ab7a 19// Last modification: Neutral cell energy included in the jet reconstruction
20//
21// Authors: Rafael.Diaz.Valdes@cern.ch
22// Magali.estienne@subatech.in2p3.fr (neutral part + bg subtraction option)
392c9b47 23//
a17e6965 24//---------------------------------------------------------------------
25
8838ab7a 26
a17e6965 27#include <Riostream.h>
28#include <TLorentzVector.h>
29#include <TFile.h>
30#include <TH1F.h>
31#include <TH2F.h>
32#include <TArrayF.h>
a17e6965 33#include <TClonesArray.h>
34
35#include "AliFastJetFinder.h"
8838ab7a 36#include "AliFastJetHeaderV1.h"
a17e6965 37#include "AliJetReaderHeader.h"
38#include "AliJetReader.h"
8838ab7a 39#include "AliJetUnitArray.h"
d1993270 40#include "AliFastJetInput.h"
41#include "AliJetBkg.h"
b8bf1e90 42#include "AliAODJetEventBackground.h"
392c9b47 43
44#include "fastjet/PseudoJet.hh"
45#include "fastjet/ClusterSequenceArea.hh"
46#include "fastjet/AreaDefinition.hh"
47#include "fastjet/JetDefinition.hh"
48// get info on how fastjet was configured
49#include "fastjet/config.h"
50
51#ifdef ENABLE_PLUGIN_SISCONE
52#include "fastjet/SISConePlugin.hh"
53#endif
54
55#include<sstream> // needed for internal io
56#include<vector>
57#include <cmath>
58
59using namespace std;
a17e6965 60
61
9157b9c9 62ClassImp(AliFastJetFinder)
8838ab7a 63
64
392c9b47 65//____________________________________________________________________________
a17e6965 66
67AliFastJetFinder::AliFastJetFinder():
856618e7 68 AliJetFinder(),
287697fc 69 fInputFJ(new AliFastJetInput()),
70 fJetBkg(new AliJetBkg())
a17e6965 71{
72 // Constructor
73}
74
392c9b47 75//____________________________________________________________________________
a17e6965 76
77AliFastJetFinder::~AliFastJetFinder()
a17e6965 78{
79 // destructor
287697fc 80 delete fInputFJ; fInputFJ = 0;
81 delete fJetBkg; fJetBkg = 0;
a17e6965 82}
83
392c9b47 84//______________________________________________________________________________
a17e6965 85void AliFastJetFinder::FindJets()
a17e6965 86{
d1993270 87 cout<<"----------in AliFastJetFinder::FindJets() ------------------"<<endl;
392c9b47 88 //pick up fastjet header
8838ab7a 89 AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
90 Bool_t debug = header->GetDebug(); // debug option
91 Bool_t bgMode = header->GetBGMode(); // choose to subtract BG or not
392c9b47 92
93 // check if we are reading AOD jets
94 TRefArray *refs = 0;
95 Bool_t fromAod = !strcmp(fReader->ClassName(),"AliJetAODReader");
96 if (fromAod) { refs = fReader->GetReferences(); }
97
98 // RUN ALGORITHM
99 // read input particles -----------------------------
d1993270 100
101 vector<fastjet::PseudoJet> inputParticles=fInputFJ->GetInputParticles();
102
103
392c9b47 104 // create an object that represents your choice of jet algorithm, and
105 // the associated parameters
3dda898d 106 double rParam = header->GetRparam();
392c9b47 107 fastjet::Strategy strategy = header->GetStrategy();
3dda898d 108 fastjet::RecombinationScheme recombScheme = header->GetRecombScheme();
392c9b47 109 fastjet::JetAlgorithm algorithm = header->GetAlgorithm();
d1993270 110 fastjet::JetDefinition jetDef(algorithm, rParam, recombScheme, strategy);
8838ab7a 111
392c9b47 112 // create an object that specifies how we to define the area
3dda898d 113 fastjet::AreaDefinition areaDef;
114 double ghostEtamax = header->GetGhostEtaMax();
115 double ghostArea = header->GetGhostArea();
116 int activeAreaRepeats = header->GetActiveAreaRepeats();
392c9b47 117
118 // now create the object that holds info about ghosts
d1993270 119 fastjet::GhostedAreaSpec ghostSpec(ghostEtamax, activeAreaRepeats, ghostArea);
392c9b47 120 // and from that get an area definition
3dda898d 121 fastjet::AreaType areaType = header->GetAreaType();
d1993270 122 areaDef = fastjet::AreaDefinition(areaType,ghostSpec);
392c9b47 123
8838ab7a 124 if(bgMode) // BG subtraction
125 {
126 //***************************** JETS FINDING AND EXTRACTION
127 // run the jet clustering with the above jet definition
d1993270 128 fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef, areaDef);
392c9b47 129
8838ab7a 130 // save a comment in the header
131
132 TString comment = "Running FastJet algorithm with the following setup. ";
133 comment+= "Jet definition: ";
d1993270 134 comment+= TString(jetDef.description());
8838ab7a 135 comment+= ". Area definition: ";
3dda898d 136 comment+= TString(areaDef.description());
8838ab7a 137 comment+= ". Strategy adopted by FastJet: ";
138 comment+= TString(clust_seq.strategy_string());
139 header->SetComment(comment);
140 if(debug){
141 cout << "--------------------------------------------------------" << endl;
142 cout << comment << endl;
143 cout << "--------------------------------------------------------" << endl;
144 }
145 //header->PrintParameters();
146
147
148 // extract the inclusive jets with pt > ptmin, sorted by pt
149 double ptmin = header->GetPtMin();
3dda898d 150 vector<fastjet::PseudoJet> inclusiveJets = clust_seq.inclusive_jets(ptmin);
8838ab7a 151
152 //cout << "Number of unclustered particles: " << clust_seq.unclustered_particles().size() << endl;
153
154
155 //subtract background // ===========================================
156 // set the rapididty , phi range within which to study the background
3dda898d 157 double rapMax = header->GetRapMax();
158 double rapMin = header->GetRapMin();
159 double phiMax = header->GetPhiMax();
160 double phiMin = header->GetPhiMin();
161 fastjet::RangeDefinition range(rapMin, rapMax, phiMin, phiMax);
8838ab7a 162
163 // subtract background
3dda898d 164 vector<fastjet::PseudoJet> subJets = clust_seq.subtracted_jets(range,ptmin);
8838ab7a 165
166 // print out
167 //cout << "Printing inclusive sub jets with pt > "<< ptmin<<" GeV\n";
168 //cout << "---------------------------------------\n";
169 //cout << endl;
170 //printf(" ijet rap phi Pt area +- err\n");
171
172 // sort jets into increasing pt
3dda898d 173 vector<fastjet::PseudoJet> jets = sorted_by_pt(subJets);
8838ab7a 174 for (size_t j = 0; j < jets.size(); j++) { // loop for jets
175
176 double area = clust_seq.area(jets[j]);
3dda898d 177 double areaError = clust_seq.area_error(jets[j]);
8838ab7a 178
3dda898d 179 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);
392c9b47 180
181 // go to write AOD info
8838ab7a 182 AliAODJet aodjet (jets[j].px(), jets[j].py(), jets[j].pz(), jets[j].E());
183 //cout << "Printing jet " << endl;
184 if(debug) aodjet.Print("");
185 //cout << "Adding jet ... " ;
186 AddJet(aodjet);
187 //cout << "added \n" << endl;
188
189 }
190 }
191 else { // No BG subtraction
d1993270 192
193 TClonesArray* fUnit = fReader->GetUnitArray();
194 if(fUnit == 0) { cout << "Could not get the momentum array" << endl; return; }
195 Int_t nIn = fUnit->GetEntries();
196 cout<<"===== check Unit Array in AliFastJetFinder ========="<<endl;
197 Int_t ppp=0;
198 for(Int_t ii=0; ii<nIn; ii++)
199 {
200 AliJetUnitArray *uArray = (AliJetUnitArray*)fUnit->At(ii);
201 if(uArray->GetUnitEnergy()>0.){
202 Float_t eta = uArray->GetUnitEta();
203 Float_t phi = uArray->GetUnitPhi();
204 cout<<"ipart = "<<ppp<<" eta="<<eta<<" phi="<<phi<<endl;
205 ppp++;
206 }
207 }
392c9b47 208
d1993270 209 //fastjet::ClusterSequence clust_seq(inputParticles, jetDef);
210 fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef, areaDef);
211
8838ab7a 212 // save a comment in the header
213
214 TString comment = "Running FastJet algorithm with the following setup. ";
215 comment+= "Jet definition: ";
d1993270 216 comment+= TString(jetDef.description());
8838ab7a 217 comment+= ". Strategy adopted by FastJet: ";
218 comment+= TString(clust_seq.strategy_string());
219 header->SetComment(comment);
220 if(debug){
221 cout << "--------------------------------------------------------" << endl;
222 cout << comment << endl;
223 cout << "--------------------------------------------------------" << endl;
224 }
225 //header->PrintParameters();
226
227 // extract the inclusive jets with pt > ptmin, sorted by pt
228 double ptmin = header->GetPtMin();
3dda898d 229 vector<fastjet::PseudoJet> inclusiveJets = clust_seq.inclusive_jets(ptmin);
8838ab7a 230
231 //cout << "Number of unclustered particles: " << clust_seq.unclustered_particles().size() << endl;
392c9b47 232
3dda898d 233 vector<fastjet::PseudoJet> jets = sorted_by_pt(inclusiveJets); // Added by me
8838ab7a 234 for (size_t j = 0; j < jets.size(); j++) { // loop for jets // Added by me
235
236 printf("Jet found %5d %9.5f %8.5f %10.3f \n",(Int_t)j,jets[j].rap(),jets[j].phi(),jets[j].perp());
d1993270 237
238 vector<fastjet::PseudoJet> constituents = clust_seq.constituents(jets[j]);
239 int nCon= constituents.size();
240 TArrayI ind(nCon);
241 Double_t area=clust_seq.area(jets[j]);
242 cout<<"area = "<<area<<endl;
8838ab7a 243 // go to write AOD info
244 AliAODJet aodjet (jets[j].px(), jets[j].py(), jets[j].pz(), jets[j].E());
d1993270 245 aodjet.SetEffArea(area,0);
8838ab7a 246 //cout << "Printing jet " << endl;
247 if(debug) aodjet.Print("");
d1993270 248 // cout << "Adding jet ... " <<j<<endl;
249 for (int i=0; i < nCon; i++)
250 {
251 fastjet::PseudoJet mPart=constituents[i];
252 ind[i]=mPart.user_index();
253 //cout<<i<<" index="<<ind[i]<<endl;
254
255 //internal oop over all the unit cells
256 Int_t ipart = 0;
257 for(Int_t ii=0; ii<nIn; ii++)
258 {
259 AliJetUnitArray *uArray = (AliJetUnitArray*)fUnit->At(ii);
260 if(uArray->GetUnitEnergy()>0.){
261 uArray->SetUnitTrackID(ipart);//used to have the index available in AliJEtBkg
262 if(ipart==ind[i]){
263 aodjet.AddTrack(uArray);
264 }
265 ipart++;
266 }
267 }
268 }
269
8838ab7a 270 AddJet(aodjet);
271 //cout << "added \n" << endl;
d1993270 272
273
274 ///----> set in the aod the reference to the unit cells
275 // in FastJetFinder: 1) loop over the unit array. 2) select those unit cells belonging to the jet (via user_index). 3) use AliAODJet->AddTrack(unitRef)
276 // in AliJetBkg: 1) loop over the unit arrays --> get ind of the unit cell 2) internal loop on jet unit cells; 3) check if i_cell = UID of the trackRefs of the AODJet
277 // should work hopefully
278
279
8838ab7a 280
281 } // end loop for jets
282 }
283
a17e6965 284}
285
392c9b47 286//____________________________________________________________________________
287void AliFastJetFinder::RunTest(const char* datafile)
a17e6965 288
a17e6965 289{
a17e6965 290
392c9b47 291 // This simple test run the kt algorithm for an ascii file testdata.dat
292 // read input particles -----------------------------
3dda898d 293 vector<fastjet::PseudoJet> inputParticles;
392c9b47 294 Float_t px,py,pz,en;
295 ifstream in;
296 Int_t nlines = 0;
297 // we assume a file basic.dat in the current directory
298 // this file has 3 columns of float data
299 in.open(datafile);
300 while (1) {
301 in >> px >> py >> pz >> en;
302 if (!in.good()) break;
303 //printf("px=%8f, py=%8f, pz=%8fn",px,py,pz);
304 nlines++;
3dda898d 305 inputParticles.push_back(fastjet::PseudoJet(px,py,pz,en));
a17e6965 306 }
392c9b47 307 //printf(" found %d pointsn",nlines);
308 in.close();
309 //////////////////////////////////////////////////
310
311 // create an object that represents your choice of jet algorithm, and
312 // the associated parameters
3dda898d 313 double rParam = 1.0;
392c9b47 314 fastjet::Strategy strategy = fastjet::Best;
3dda898d 315 fastjet::RecombinationScheme recombScheme = fastjet::BIpt_scheme;
d1993270 316 fastjet::JetDefinition jetDef(fastjet::kt_algorithm, rParam, recombScheme, strategy);
392c9b47 317
318
319
320 // create an object that specifies how we to define the area
3dda898d 321 fastjet::AreaDefinition areaDef;
322 double ghostEtamax = 7.0;
323 double ghostArea = 0.05;
324 int activeAreaRepeats = 1;
392c9b47 325
326
327 // now create the object that holds info about ghosts
d1993270 328 fastjet::GhostedAreaSpec ghostSpec(ghostEtamax, activeAreaRepeats, ghostArea);
392c9b47 329 // and from that get an area definition
d1993270 330 areaDef = fastjet::AreaDefinition(fastjet::active_area,ghostSpec);
392c9b47 331
332
333 // run the jet clustering with the above jet definition
d1993270 334 fastjet::ClusterSequenceArea clust_seq(inputParticles, jetDef, areaDef);
392c9b47 335
336
337 // tell the user what was done
338 cout << "--------------------------------------------------------" << endl;
d1993270 339 cout << "Jet definition was: " << jetDef.description() << endl;
3dda898d 340 cout << "Area definition was: " << areaDef.description() << endl;
392c9b47 341 cout << "Strategy adopted by FastJet was "<< clust_seq.strategy_string()<<endl<<endl;
342 cout << "--------------------------------------------------------" << endl;
343
344
345 // extract the inclusive jets with pt > 5 GeV, sorted by pt
346 double ptmin = 5.0;
3dda898d 347 vector<fastjet::PseudoJet> inclusiveJets = clust_seq.inclusive_jets(ptmin);
392c9b47 348
349 cout << "Number of unclustered particles: " << clust_seq.unclustered_particles().size() << endl;
350
351
352 //subtract background // ===========================================
353 // set the rapididty range within which to study the background
3dda898d 354 double rapMax = ghostEtamax - rParam;
355 fastjet::RangeDefinition range(rapMax);
392c9b47 356 // subtract background
3dda898d 357 vector<fastjet::PseudoJet> subJets = clust_seq.subtracted_jets(range,ptmin);
392c9b47 358
359 // print them out //================================================
360 cout << "Printing inclusive jets after background subtraction \n";
361 cout << "------------------------------------------------------\n";
362 // sort jets into increasing pt
3dda898d 363 vector<fastjet::PseudoJet> jets = sorted_by_pt(subJets);
392c9b47 364
365 printf(" ijet rap phi Pt area +- err\n");
366 for (size_t j = 0; j < jets.size(); j++) {
367
368 double area = clust_seq.area(jets[j]);
3dda898d 369 double areaError = clust_seq.area_error(jets[j]);
392c9b47 370
8838ab7a 371 printf("%5d %9.5f %8.5f %10.3f %8.3f +- %6.3f\n",(Int_t)j,jets[j].rap(),
3dda898d 372 jets[j].phi(),jets[j].perp(), area, areaError);
392c9b47 373 }
374 cout << endl;
375 // ================================================================
a17e6965 376
392c9b47 377
378
a17e6965 379}
380
392c9b47 381//____________________________________________________________________________
a17e6965 382
383void AliFastJetFinder::WriteJHeaderToFile()
384{
a17e6965 385 fHeader->Write();
386}
387
9157b9c9 388//____________________________________________________________________________
8838ab7a 389
390Float_t AliFastJetFinder::EtaToTheta(Float_t arg)
391{
392 // return (180./TMath::Pi())*2.*atan(exp(-arg));
393 return 2.*atan(exp(-arg));
394
395
396}
397
398//____________________________________________________________________________
399
400void AliFastJetFinder::InitTask(TChain *tree)
401{
402
403 printf("Fast jet finder initialization ******************");
404 fReader->CreateTasks(tree);
405
406}
d1993270 407
287697fc 408
409Bool_t AliFastJetFinder::ProcessEvent()
410{
411 //
412 // Process one event
413 // from meomntum array
414
415 Bool_t ok = fReader->FillMomentumArray();
416
417 if (!ok) return kFALSE;
418 fInputFJ->SetHeader(fHeader);
419 fInputFJ->SetReader(fReader);
420 fInputFJ->FillInput();
421 // Jets
422 FindJets();
423
424 fJetBkg->SetHeader(fHeader);
425 fJetBkg->SetReader(fReader);
426 /*
427 fJetBkg->SetFastJetInput(fInputFJ);
428 Double_t bkg1=fJetBkg->BkgFastJet();
429 Double_t bkg2=fJetBkg->BkgChargedFastJet();
430 Double_t bkg3=fJetBkg->BkgFastJetCone(fAODjets);
431 Double_t bkg4=fJetBkg->BkgRemoveJetLeading(fAODjets);
432
433 fAODEvBkg->SetBackground(0,bkg1);
434 fAODEvBkg->SetBackground(1,bkg2);
435 fAODEvBkg->SetBackground(2,bkg3);
436 fAODEvBkg->SetBackground(3,bkg4);
437 */
438 Reset();
439 return kTRUE;
440
441}
442
d1993270 443Bool_t AliFastJetFinder::ProcessEvent2()
444{
445 //
446 // Process one event
447 // Charged only or charged+neutral jets
448 //
449
450 TRefArray* ref = new TRefArray();
451 Bool_t procid = kFALSE;
452 Bool_t ok = fReader->ExecTasks(procid,ref);
453
454 // Delete reference pointer
455 if (!ok) {delete ref; return kFALSE;}
456
457 // Leading particles
458 fInputFJ->SetHeader(fHeader);
459 fInputFJ->SetReader(fReader);
460 fInputFJ->FillInput();
461
462 // Jets
463 FindJets();
464
465 fJetBkg->SetHeader(fHeader);
466 fJetBkg->SetReader(fReader);
467 fJetBkg->SetFastJetInput(fInputFJ);
468 Double_t bkg1=fJetBkg->BkgFastJet();
469 Double_t bkg2=fJetBkg->BkgChargedFastJet();
470 Double_t bkg3=fJetBkg->BkgFastJetCone(fAODjets);
471 Double_t bkg4=fJetBkg->BkgRemoveJetLeading(fAODjets);
472
473 fAODEvBkg->SetBackground(0,bkg1);
474 fAODEvBkg->SetBackground(1,bkg2);
475 fAODEvBkg->SetBackground(2,bkg3);
476 fAODEvBkg->SetBackground(3,bkg4);
477
478 Int_t nEntRef = ref->GetEntries();
479
480 for(Int_t i=0; i<nEntRef; i++)
481 {
482 // Reset the UnitArray content which were referenced
483 ((AliJetUnitArray*)ref->At(i))->SetUnitTrackID(0);
484 ((AliJetUnitArray*)ref->At(i))->SetUnitEnergy(0.);
485 ((AliJetUnitArray*)ref->At(i))->SetUnitCutFlag(kPtSmaller);
486 ((AliJetUnitArray*)ref->At(i))->SetUnitCutFlag2(kPtSmaller);
487 ((AliJetUnitArray*)ref->At(i))->SetUnitSignalFlag(kBad);
488 ((AliJetUnitArray*)ref->At(i))->SetUnitSignalFlagC(kTRUE,kBad);
489 ((AliJetUnitArray*)ref->At(i))->SetUnitDetectorFlag(kTpc);
490 ((AliJetUnitArray*)ref->At(i))->SetUnitFlag(kOutJet);
491 ((AliJetUnitArray*)ref->At(i))->ClearUnitTrackRef();
492
493 // Reset process ID
494 AliJetUnitArray* uA = (AliJetUnitArray*)ref->At(i);
495 uA->ResetBit(kIsReferenced);
496 uA->SetUniqueID(0);
497 }
498
499 // Delete the reference pointer
500 ref->Delete();
501 delete ref;
502
503 Reset();
504
505 return kTRUE;
506}