]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/AliFastJetInput.cxx
Coverity corrections
[u/mrichter/AliRoot.git] / JETAN / AliFastJetInput.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 #include <Riostream.h> 
17 #include <TChain.h>
18 #include <TFile.h>
19 #include <TF1.h>
20 #include <TRandom.h>
21 #include <TList.h>
22 #include <TLorentzVector.h>
23 #include <TArrayF.h>
24 #include <TClonesArray.h>
25
26 #include "AliJetHeader.h"
27 #include "AliJetReader.h"
28 #include "AliJetReaderHeader.h"
29 #include "AliJetHistos.h"
30
31 #include "AliFastJetFinder.h"
32 #include "AliFastJetHeaderV1.h"
33 #include "AliJetReaderHeader.h"
34 #include "AliJetReader.h"
35 #include "AliJetESDReader.h"
36 #include "AliJetUnitArray.h"
37 #include "AliFastJetInput.h"
38
39 #include "fastjet/PseudoJet.hh"
40 #include "fastjet/ClusterSequenceArea.hh"
41 #include "fastjet/AreaDefinition.hh"
42 #include "fastjet/JetDefinition.hh"
43 // get info on how fastjet was configured
44 #include "fastjet/config.h"
45
46 #ifdef ENABLE_PLUGIN_SISCONE
47 #include "fastjet/SISConePlugin.hh"
48 #endif
49
50 #include<sstream>  // needed for internal io
51 #include<vector> 
52 #include <cmath> 
53
54 using namespace std;
55
56
57 ClassImp(AliFastJetInput)
58
59 ////////////////////////////////////////////////////////////////////////
60
61 AliFastJetInput::AliFastJetInput():
62     fReader(0),
63     fHeader(0),
64     fInputParticles(0),
65     fInputParticlesCh(0)
66 {
67   // Default constructor
68 }
69 AliFastJetInput::AliFastJetInput(const AliFastJetInput &input):
70     TObject(),
71     fReader(input.fReader),
72     fHeader(input.fHeader),
73     fInputParticles(input.fInputParticles),
74     fInputParticlesCh(input.fInputParticlesCh)
75 {
76   // copy constructor
77 }
78 //______________________________________________________________________
79 AliFastJetInput& AliFastJetInput::operator=(const AliFastJetInput& source){
80     // Assignment operator. 
81     this->~AliFastJetInput();
82     new(this) AliFastJetInput(source);
83     return *this;
84
85 }
86 //___________________________________________________________
87 void AliFastJetInput::FillInput(){
88   //cout<<"-------- AliFastJetInput::FillInput()  ----------------"<<endl;
89
90   AliFastJetHeaderV1 *header = (AliFastJetHeaderV1*)fHeader;
91   fInputParticles.clear();
92   fInputParticlesCh.clear();
93
94   Int_t debug  = header->GetDebug();     // debug option
95   Int_t fOpt   = fReader->GetReaderHeader()->GetDetector();
96
97   // check if we are reading AOD jets
98   Bool_t fromAod = !strcmp(fReader->ClassName(),"AliJetAODReader");
99   
100   // RUN ALGORITHM  
101   // read input particles -----------------------------
102   vector<fastjet::PseudoJet> inputParticles;
103   //  cout<<"=============== AliFastJetInput::FillInput()  =========== fOpt="<<fOpt<<endl;
104   //cout<<"pointers --> fReader="<<fReader<<" header="<<header<<" fHeader="<<fHeader<<endl;
105   //cout<<"Rparam="<<Rparam<<"  ghost_etamax="<<ghost_etamax<<"  ghost_area="<<ghost_area<<endl;
106   //cout<<fReader->ClassName()<<endl;
107
108   if(fOpt==0)
109     {
110       TClonesArray *lvArray = fReader->GetMomentumArray();
111       if(lvArray == 0) { cout << "Could not get the momentum array" << endl; return; }
112       Int_t nIn =  lvArray->GetEntries();
113       if(nIn == 0) { if (debug) cout << "entries = 0 ; Event empty !!!" << endl ; return; }
114       Float_t px,py,pz,en;
115       // load input vectors
116       for(Int_t i = 0; i < nIn; i++){ // loop for all input particles
117         TLorentzVector *lv = (TLorentzVector*) lvArray->At(i);
118         px = lv->Px();
119         py = lv->Py();
120         pz = lv->Pz();
121         en = lv->Energy();
122         //      cout<<"in FillInput...... "<<i<<" "<<px<<" "<<py<<"  "<<pz<<" "<<en<<endl;
123         fastjet::PseudoJet inputPart(px,py,pz,en); // create PseudoJet object
124         inputPart.set_user_index(i); //label the particle into Fastjet algortihm
125         fInputParticles.push_back(inputPart);  // back of the inputParticles vector  
126       } // end loop 
127     }
128   else {
129     TClonesArray* fUnit = fReader->GetUnitArray();
130     if(fUnit == 0) { cout << "Could not get the momentum array" << endl; return; }
131     Int_t         nIn = fUnit->GetEntries();
132     if(nIn == 0) { if (debug) cout << "entries = 0 ; Event empty !!!" << endl ; return; }
133    
134     // Information extracted from fUnitArray
135     // load input vectors and calculate total energy in array
136     Float_t pt,eta,phi,theta,px,py,pz,en;
137     Int_t ipart = 0;
138     Int_t countUnit=0,countUnitNonZero=0;
139     //cout<<" nIn = "<<nIn<<endl;
140
141     for(Int_t i=0; i<nIn; i++) 
142       {
143         AliJetUnitArray *uArray = (AliJetUnitArray*)fUnit->At(i);
144         if(uArray->GetUnitEnergy()>0.){
145           countUnit++;
146           // It is not necessary anymore to cut on particle pt
147           pt    = uArray->GetUnitEnergy();
148           eta   = uArray->GetUnitEta();
149           phi   = uArray->GetUnitPhi();
150           theta = EtaToTheta(eta);
151           en    = (TMath::Abs(TMath::Sin(theta)) == 0) ? pt : pt/TMath::Abs(TMath::Sin(theta));
152           px    = TMath::Cos(phi)*pt;
153           py    = TMath::Sin(phi)*pt;
154           pz    = en*TMath::TanH(eta);
155           if(debug) cout << "pt: " << pt << ", eta: " << eta << ", phi: " << phi << ", en: " << en << ", px: " << px << ", py: " << py << ", pz: " << pz << endl;
156           //cout << i<<" "<<"pt: " << pt << ", eta: " << eta << ", phi: " << phi << ", en: " << en << ", px: " << px << ", py: " << py << ", pz: " << pz << endl;
157           //cout<<"in FillInput...... "<<i<<" "<<px<<" "<<py<<"  "<<pz<<" "<<en<<endl;
158
159           fastjet::PseudoJet inputPart(px,py,pz,en); // create PseudoJet object
160           inputPart.set_user_index(ipart); //label the particle into Fastjet algortihm
161           fInputParticles.push_back(inputPart);  // back of the inputParticles vector 
162           ipart++;
163
164         
165         
166           //only for charged particles (TPC+ITS)
167           TRefArray* ref = uArray->GetUnitTrackRef();
168           Int_t nRef = ref->GetEntries();
169           for(Int_t j=0; j<nRef;j++){
170             Float_t pxj=0.;  Float_t pyj=0.;  Float_t pzj=0.;Float_t enj=0.;
171             pxj = ((AliVTrack*)ref->At(j))->Px();
172             pyj = ((AliVTrack*)ref->At(j))->Py();
173             pzj = ((AliVTrack*)ref->At(j))->Pz();
174             enj=TMath::Sqrt(pxj*pxj+pyj*pyj+pzj*pzj);
175             fastjet::PseudoJet inputPartCh(pxj,pyj,pzj,enj); // create PseudoJet object
176             inputPartCh.set_user_index(((AliVTrack*)ref->At(j))->GetID()); //label the particle into Fastjet algortihm
177             fInputParticlesCh.push_back(inputPartCh);  // back of the inputParticles vector 
178
179           }
180         }
181       } // End loop on UnitArray 
182     if (debug) cout<<"countUnit(En>0) = "<<countUnit<<"  countUnit with Non ZeroSize = "<<countUnitNonZero<<endl;
183   }
184
185 }
186
187 //_____________________________________________________________________
188 Float_t  AliFastJetInput::EtaToTheta(Float_t arg)
189 {
190   //  return (180./TMath::Pi())*2.*atan(exp(-arg));
191   return 2.*atan(exp(-arg));
192
193
194 }
195 Double_t AliFastJetInput::Thermalspectrum(Double_t *x, Double_t *par){
196
197   return x[0]*TMath::Exp(-x[0]/par[0]);
198
199 }