]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/AliSISConeJetFinder.cxx
Coverity fix.
[u/mrichter/AliRoot.git] / JETAN / AliSISConeJetFinder.cxx
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  
16
17 //---------------------------------------------------------------------
18 // FastJet v2.3.4 finder algorithm interface
19 //
20 // Author: swensy.jangal@ires.in2p3.fr 
21 //
22 // Last modification: Neutral cell energy included in the jet reconstruction
23 //
24 // Author: Magali.estienne@subatech.in2p3.fr 
25 //---------------------------------------------------------------------
26
27
28 #include <Riostream.h>
29 #include <TArrayF.h>
30 #include <TFile.h>
31 #include <TH1F.h>
32 #include <TH2F.h>
33 #include <TLorentzVector.h>
34 #include <TRandom.h>
35 #include <TClonesArray.h>
36
37 #include "AliHeader.h"
38 #include "AliJetKineReader.h"
39 #include "AliJetReader.h"
40 #include "AliJetReaderHeader.h"
41 #include "AliJetUnitArray.h"
42 #include "AliSISConeJetFinder.h"
43 #include "AliSISConeJetHeader.h"
44
45 #include "fastjet/AreaDefinition.hh"
46 #include "fastjet/ClusterSequenceArea.hh"
47 #include "fastjet/JetDefinition.hh"
48 #include "fastjet/PseudoJet.hh"
49
50 // get info on how fastjet was configured
51 #include "fastjet/config.h"
52
53 #ifdef ENABLE_PLUGIN_SISCONE
54 #include "fastjet/SISConePlugin.hh"
55 #endif
56
57 #include<sstream>  // needed for internal io
58 #include<vector> 
59 #include <cmath> 
60
61 using namespace std;
62
63
64 ClassImp(AliSISConeJetFinder)
65
66
67 //____________________________________________________________________________
68
69 AliSISConeJetFinder::AliSISConeJetFinder():
70 AliJetFinder()
71 {
72   // Constructor
73 }
74
75 //____________________________________________________________________________
76
77 AliSISConeJetFinder::~AliSISConeJetFinder()
78 {
79   // destructor
80 }
81
82 //______________________________________________________________________________
83 void AliSISConeJetFinder::FindJets()
84 {
85
86   // Pick up siscone header
87   AliSISConeJetHeader *header = (AliSISConeJetHeader*)fHeader;
88   Int_t debug  = header->GetDebug();     // debug option
89   Int_t fOpt    = fReader->GetReaderHeader()->GetDetector();
90
91   // Check if we are reading AOD jets
92   Bool_t fromAod = !strcmp(fReader->ClassName(),"AliJetAODReader");
93
94 //******************************** SISCONE PLUGIN CONFIGURATION
95 // Here we look for SISCone parameters in the header and we define our plugin.  
96
97   Double_t coneRadius                = header->GetConeRadius();                 // cone radius
98   Double_t overlapThreshold          = header->GetOverlapThreshold();           // overlap parameter
99   Int_t    nPassMax                  = header->GetNPassMax();                   // maximum number of passes
100   Double_t ptProtoJetMin             = header->GetPtProtojetMin();              // pT min of protojets
101   Double_t caching                   = header->GetCaching();                    // do we record found cones for this set of data?
102
103 //  if (header->GetSplitMergeScale() == 0) fastjet::SISConePlugin::SplitMergeScale splitMergeScale = fastjet::SISConePlugin::SM_pttilde; // There's only one split merge scale
104 //  Double_t splitMergeStoppingScale = header->GetSplitMergeStoppingScale(); // Additional cut on pt_tilde of protojets
105
106   fastjet::JetDefinition::Plugin * plugin;
107   plugin = new fastjet::SISConePlugin(coneRadius, overlapThreshold, nPassMax, ptProtoJetMin, caching);
108
109   vector<fastjet::PseudoJet> inputParticles; 
110 //********************************  READING OF INPUT PARTICLES
111 // Here we look for px, py pz and energy of each particle that we gather in a PseudoJet object, and we put all these PseudoJet in a vector of PseudoJets : input_particles. 
112
113     if(fOpt==0) 
114       {
115         TClonesArray *lvArray = fReader->GetMomentumArray();
116
117         
118         // We check if lvArray is ok
119         if(lvArray == 0)
120           {
121             cout << "Could not get the momentum array" << endl;
122             delete plugin;
123             return;
124           }
125         
126         Int_t nIn = lvArray->GetEntries();
127         
128         if(nIn == 0)// nIn = Number of particles in the event
129           {
130             if (debug) cout << "entries = 0 ; Event empty !!!" << endl ;
131             delete plugin;
132             return;
133           }
134         
135         Float_t px,py,pz,en;
136         
137         // Load input vectors
138         for(Int_t i = 0; i < nIn; i++)
139           { 
140             TLorentzVector *lv = (TLorentzVector*) lvArray->At(i);
141             px = lv->Px();
142             py = lv->Py();
143             pz = lv->Pz();
144             en = lv->Energy();
145             
146             fastjet::PseudoJet inputPart(px,py,pz,en); 
147             inputPart.set_user_index(i);
148             inputParticles.push_back(inputPart); 
149             
150           }
151       }
152     else {
153       TClonesArray* fUnit = fReader->GetUnitArray();
154       if(fUnit == 0) { cout << "Could not get the momentum array" << endl;          delete plugin; return; }
155       Int_t         nIn = fUnit->GetEntries();
156       if(nIn == 0) { if (debug) cout << "entries = 0 ; Event empty !!!" << endl ;           delete plugin; return; }
157         // Information extracted from fUnitArray
158       // load input vectors and calculate total energy in array
159       Float_t pt,eta,phi,theta,px,py,pz,en;
160       Int_t ipart = 0;
161       for(Int_t i=0; i<nIn; i++) 
162         {
163           AliJetUnitArray *uArray = (AliJetUnitArray*)fUnit->At(i);
164           
165           if(uArray->GetUnitEnergy()>0.){
166             
167             // It is not necessary anymore to cut on particle pt
168             pt    = uArray->GetUnitEnergy();
169             eta   = uArray->GetUnitEta();
170             phi   = uArray->GetUnitPhi();
171             theta = EtaToTheta(eta);
172             en    = (TMath::Abs(TMath::Sin(theta)) == 0) ? pt : pt/TMath::Abs(TMath::Sin(theta));
173             px    = TMath::Cos(phi)*pt;
174             py    = TMath::Sin(phi)*pt;
175             pz    = en*TMath::TanH(eta);
176             if(debug) cout << "pt: " << pt << ", eta: " << eta << ", phi: " << phi << ", en: " << en << ", px: " << px << ", py: " << py << ", pz: " << pz << endl;
177             
178             fastjet::PseudoJet inputPart(px,py,pz,en); // create PseudoJet object
179             inputPart.set_user_index(ipart); //label the particle into Fastjet algortihm
180             inputParticles.push_back(inputPart);  // back of the input_particles vector 
181             ipart++;
182           }
183         } // End loop on UnitArray 
184     }
185   
186 //******************************** CHOICE OF JET AREA  
187 // Here we determine jets area for subtracting background later
188 // For more informations about jet areas see : The Catchment Area of Jets M. Cacciari, G. Salam and G. Soyez
189
190   Double_t ghostEtamax        = header->GetGhostEtaMax();       // maximum eta in which a ghost can be generated
191   Double_t ghostArea          = header->GetGhostArea();         // area of a ghost
192   Int_t    activeAreaRepeats  = header->GetActiveAreaRepeats(); // do we repeat area calculation?
193   Double_t gridScatter        = header->GetGridScatter();       // fractional random fluctuations of the position of the ghosts on the y-phi grid
194   Double_t ktScatter          = header->GetKtScatter();         // fractional random fluctuations of the tranverse momentum of the ghosts on the y-phi grid
195   Double_t meanGhostKt        = header->GetMeanGhostKt();       // average transverse momentum of the ghosts.
196
197   Double_t areaTypeNumber  = header->GetAreaTypeNumber();       // the number determines jet area type 
198   fastjet::AreaType areaType = fastjet::active_area;
199   if (areaTypeNumber == 1)  areaType = fastjet::active_area;                 
200   if (areaTypeNumber == 2)  areaType = fastjet::active_area_explicit_ghosts; 
201   if (areaTypeNumber == 3)  areaType = fastjet::one_ghost_passive_area;      
202   if (areaTypeNumber == 4)  areaType = fastjet::passive_area;                
203   if (areaTypeNumber == 5)  areaType = fastjet::voronoi_area;                
204
205   fastjet::AreaDefinition areaDef;
206
207   if (areaTypeNumber < 5) 
208   {
209     fastjet::GhostedAreaSpec ghostSpec(ghostEtamax, activeAreaRepeats, ghostArea, gridScatter, ktScatter, meanGhostKt);
210     areaDef = fastjet::AreaDefinition(areaType,ghostSpec);
211   }
212
213   if (areaTypeNumber == 5)
214   {
215     Double_t effectiveRFact = header->GetEffectiveRFact();
216     fastjet::VoronoiAreaSpec ghostSpec(effectiveRFact);
217     areaDef = fastjet::AreaDefinition(areaType,ghostSpec);
218   }
219
220 //********************************
221 //********************************
222
223   Bool_t bgMode = header->GetBGMode();// Here one choose to subtract BG or not
224
225 //********************************
226 //********************************
227
228 //********************************
229 //******************************** BG SUBTRACTION
230   if (bgMode == 1)// BG subtraction
231   {
232     //******************************** JETS FINDING AND EXTRACTION
233     fastjet::ClusterSequenceArea clustSeq(inputParticles, plugin, areaDef);
234     // Here we extract inclusive jets with pt > ptmin, sorted by pt 
235     Double_t ptMin = header->GetMinJetPt(); 
236     vector<fastjet::PseudoJet> inclusiveJets = clustSeq.inclusive_jets(ptMin);
237     vector<fastjet::PseudoJet> jets = sorted_by_pt(inclusiveJets);
238   
239     //***************************** BACKGROUND SUBTRACTION
240
241     // Set the rapidity-azimuth range within which to study background
242     Double_t rapMin = header->GetRapMin();
243     Double_t rapMax = header->GetRapMax();
244     Double_t phiMin = header->GetPhiMin();
245     Double_t phiMax = header->GetPhiMax();
246     fastjet::RangeDefinition range(rapMin, rapMax, phiMin, phiMax);
247
248     // rho calculus from Cambridge/Aachen clustering (not from SISCONE as it gives too small areas)
249     Int_t algo = header->GetBGAlgorithm();
250     fastjet::JetAlgorithm algorithm = fastjet::kt_algorithm;
251     if (algo == 0) algorithm = fastjet::kt_algorithm;
252     if (algo == 1) algorithm = fastjet::cambridge_algorithm;
253     Double_t RRho = header->GetRForRho();
254     fastjet::JetDefinition jetDefForRho(algorithm, RRho);
255     fastjet::ClusterSequenceArea csForRho(inputParticles, jetDefForRho, areaDef);
256     Double_t rho = csForRho.median_pt_per_unit_area_4vector(range);
257     cout<<"rho = "<<rho<<endl;
258
259     // Vector of corrected jets
260     vector<fastjet::PseudoJet> corrJets = clustSeq.subtracted_jets(rho, ptMin);
261   
262     //***************************** JETS DISPLAY
263
264     for (size_t j = 0; j < jets.size(); j++)
265     {
266       // If the jet is only made of ghosts, continue.
267       if (clustSeq.is_pure_ghost(jets[j]) == 1) continue;
268
269       // If the correction is > jet energy px = py = pz = e = 0
270       if (corrJets[j].px() == 0 && corrJets[j].py() == 0 && corrJets[j].pz() == 0 && corrJets[j].E() == 0) continue;
271
272       if(debug){
273         cout<<"********************************** Reconstructed jet(s) (non corrected)"<<endl;
274         cout<<"Jet number "<<j+1<<" : "<<"Rapidity : "<<jets[j].rap()<<" Phi : "<<jets[j].phi()<<" pT : "<<jets[j].perp()<<" area : "<<clustSeq.area(jets[j])<<endl;
275         cout<<"e = "<<jets[j].E()<<endl;
276         
277         cout<<"********************************** Corrected jet(s)"<<endl;
278         cout<<"Jet number "<<j+1<<" : "<<"Rapidity : "<<corrJets[j].rap()<<" Phi : "<<corrJets[j].phi()<<" pT : "<<corrJets[j].perp()<<endl;
279         cout<<"e = "<<corrJets[j].E()<<endl;
280       }
281       // Go to write AOD info
282       AliAODJet aodjet (corrJets[j].px(), corrJets[j].py(), corrJets[j].pz(), corrJets[j].E());
283       if(debug) aodjet.Print("");
284       AddJet(aodjet);
285     }
286   }
287
288 //********************************
289 //******************************** NO BG SUBTRACTION
290
291   if (bgMode == 0)// No BG subtraction
292   {
293     //******************************** JETS FINDING AND EXTRACTION
294     fastjet::ClusterSequenceArea clustSeq(inputParticles, plugin, areaDef);
295     // Here we extract inclusive jets with pt > ptmin, sorted by pt 
296     Double_t ptMin = header->GetMinJetPt(); 
297     vector<fastjet::PseudoJet> inclusiveJets = clustSeq.inclusive_jets(ptMin);
298     vector<fastjet::PseudoJet> jets = sorted_by_pt(inclusiveJets);
299
300     //***************************** JETS DISPLAY
301
302     for (size_t k = 0; k < jets.size(); k++)
303     {
304       if(debug)
305       {
306         cout<<"********************************** Reconstructed jet(s) (non corrected)"<<endl;
307         cout<<"Jet number "<<k+1<<" : "<<"Rapidity : "<<jets[k].rap()<<" Phi : "<<jets[k].phi()<<" pT : "<<jets[k].perp()<<endl;
308         cout<<"e = "<<jets[k].E()<<endl;
309       }
310
311       // Go to write AOD info
312       Double_t area = clustSeq.area(jets[k]);
313       AliAODJet aodjet (jets[k].px(), jets[k].py(), jets[k].pz(), jets[k].E());
314       aodjet.SetEffArea(area,0);
315       if(debug) aodjet.Print("");
316       AddJet(aodjet);
317     }
318   }
319
320   delete plugin;
321
322 }
323  
324 //____________________________________________________________________________
325
326 Float_t  AliSISConeJetFinder::EtaToTheta(Float_t arg)
327 {
328   //  return (180./TMath::Pi())*2.*atan(exp(-arg));
329   return 2.*atan(exp(-arg));
330
331
332 }
333
334 //____________________________________________________________________________
335
336 void AliSISConeJetFinder::InitTask(TChain *tree)
337 {
338
339   printf("SISCone jet finder initialization ******************");
340   fReader->CreateTasks(tree);
341
342 }
343
344
345 //____________________________________________________________________________
346
347 void AliSISConeJetFinder::WriteJHeaderToFile() const
348 {
349   fHeader->Write();
350 }
351
352 //____________________________________________________________________________
353