]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/AliEmcalJetUtilityConstSubtractor.cxx
Reorganization of the EMCal jet finder task: the manin task only performs the basic...
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliEmcalJetUtilityConstSubtractor.cxx
1 #include "AliEmcalJetUtilityConstSubtractor.h"
2 #include "AliEmcalJet.h"
3 #include "AliRhoParameter.h"
4 #include "AliEmcalJetTask.h"
5
6 ClassImp(AliEmcalJetUtilityConstSubtractor)
7
8 //______________________________________________________________________________
9 AliEmcalJetUtilityConstSubtractor::AliEmcalJetUtilityConstSubtractor() :
10   AliEmcalJetUtility(),
11   fJetsSubName(""),
12   fParticlesSubName(""),
13   fUseExternalBkg(kFALSE),
14   fRhoName(""),
15   fRhomName(""),
16   fRho(0),
17   fRhom(0),
18   fJetsSub(0x0),
19   fParticlesSub(0x0),
20   fRhoParam(0),
21   fRhomParam(0)
22 {
23   // Dummy constructor.
24
25 }
26
27 //______________________________________________________________________________
28 AliEmcalJetUtilityConstSubtractor::AliEmcalJetUtilityConstSubtractor(const char* name) :
29   AliEmcalJetUtility(name),
30   fJetsSubName(""),
31   fParticlesSubName(""),
32   fUseExternalBkg(kFALSE),
33   fRhoName(""),
34   fRhomName(""),
35   fRho(0),
36   fRhom(0),
37   fJetsSub(0x0),
38   fParticlesSub(0x0),
39   fRhoParam(0),
40   fRhomParam(0)
41 {
42   // Default constructor.
43 }
44
45 //______________________________________________________________________________
46 AliEmcalJetUtilityConstSubtractor::AliEmcalJetUtilityConstSubtractor(const AliEmcalJetUtilityConstSubtractor &other) :
47   AliEmcalJetUtility(other),
48   fJetsSubName(other.fJetsSubName),
49   fParticlesSubName(other.fParticlesSubName),
50   fUseExternalBkg(other.fUseExternalBkg),
51   fRhoName(other.fRhoName),
52   fRhomName(other.fRhomName),
53   fRho(other.fRho),
54   fRhom(other.fRhom),
55   fJetsSub(other.fJetsSub),
56   fParticlesSub(other.fParticlesSub),
57   fRhoParam(other.fRhoParam),
58   fRhomParam(other.fRhomParam)
59 {
60   // Copy constructor.
61 }
62
63 //______________________________________________________________________________
64 AliEmcalJetUtilityConstSubtractor& AliEmcalJetUtilityConstSubtractor::operator=(const AliEmcalJetUtilityConstSubtractor &other)
65 {
66   // Assignment.
67
68   if (&other == this) return *this;
69   AliEmcalJetUtility::operator=(other);
70   fJetsSubName = other.fJetsSubName;
71   fParticlesSubName = other.fParticlesSubName;
72   fUseExternalBkg = other.fUseExternalBkg;
73   fRhoName = other.fRhoName;
74   fRhomName = other.fRhomName;
75   fRho = other.fRho;
76   fRhom = other.fRhom;
77   fJetsSub = other.fJetsSub;
78   fParticlesSub = other.fParticlesSub;
79   fRhoParam = other.fRhoParam;
80   fRhomParam = other.fRhomParam;
81   return *this;
82 }
83
84 //______________________________________________________________________________
85 void AliEmcalJetUtilityConstSubtractor::Init()
86 {
87   // Initialize the utility.
88
89   // Add constituent subtracted jets to event
90   if (!fJetsSubName.IsNull()) {
91     if (!(fJetTask->GetEvent()->FindListObject(fJetsSubName)) ) {
92       fJetsSub = new TClonesArray("AliEmcalJet");
93       fJetsSub->SetName(fJetsSubName);
94       fJetTask->GetEvent()->AddObject(fJetsSub);
95     } 
96     else {
97       AliError(Form("%s: Object for subtracted jet branch with name %s already in event! Returning", GetName(), fJetsSubName.Data()));
98       return;
99     }
100   }
101
102   // Add tracks from constituent subtracted jets to event
103   if (!fParticlesSubName.IsNull()) {
104     if (!(fJetTask->GetEvent()->FindListObject(fParticlesSubName))) {
105       fParticlesSub = new TClonesArray("AliEmcalParticle");
106       fParticlesSub->SetName(fParticlesSubName);
107       fJetTask->GetEvent()->AddObject(fParticlesSub);
108     } else {
109       AliError(Form("%s: Object with name %s already in event! Returning", GetName(), fParticlesSubName.Data()));
110       return;
111     }
112   }
113
114   if (!fRhoName.IsNull() && !fRhoParam) { // get rho from the event
115     fRhoParam = dynamic_cast<AliRhoParameter*>(fJetTask->GetEvent()->FindListObject(fRhoName));
116     if (!fRhoParam) {
117       AliError(Form("%s: Could not retrieve rho %s!", GetName(), fRhoName.Data()));
118       return;
119     }
120   }
121
122   if (!fRhomName.IsNull() && !fRhomParam) { // get rhom from the event
123     fRhomParam = dynamic_cast<AliRhoParameter*>(fJetTask->GetEvent()->FindListObject(fRhomName));
124     if (!fRhomParam) {
125       AliError(Form("%s: Could not retrieve rho_m %s!", GetName(), fRhomName.Data()));
126       return;
127     }
128   }
129
130   fInit = kTRUE;
131 }
132
133 //______________________________________________________________________________
134 void AliEmcalJetUtilityConstSubtractor::Prepare(AliFJWrapper& fjw)
135 {
136   // Prepare the utility.
137
138   if (!fInit) return;
139
140   if (fRhoParam) fRho = fRhoParam->GetVal();
141   if (fRhomParam) fRhom = fRhomParam->GetVal();
142
143   if (fJetsSub) fJetsSub->Delete();
144
145   fjw.SetUseExternalBkg(fUseExternalBkg, fRho, fRhom);
146   fjw.DoConstituentSubtraction();
147 }
148
149 //______________________________________________________________________________
150 void AliEmcalJetUtilityConstSubtractor::ProcessJet(AliEmcalJet* /*jet*/, Int_t /*ij*/, AliFJWrapper& /*fjw*/)
151 {
152   // Proceess each jet.
153 }
154
155 //______________________________________________________________________________
156 void AliEmcalJetUtilityConstSubtractor::Terminate(AliFJWrapper& fjw)
157 {
158   // Run termination of the utility (after each event).
159
160   if (!fInit) return;
161
162   if (!fJetsSub) {
163     AliWarning(Form("No jet branch to write to for subtracted jets. fJetsSubName: %s", fJetsSubName.Data()));
164     return;
165   }
166
167 #ifdef FASTJET_VERSION
168   std::vector<fastjet::PseudoJet> jets_sub;
169   jets_sub = fjw.GetConstituentSubtrJets();
170   AliDebug(1,Form("%d constituent subtracted jets found", (Int_t)jets_sub.size()));
171   for (UInt_t ijet = 0, jetCount = 0; ijet < jets_sub.size(); ++ijet) {
172     //Only storing 4-vector and jet area of unsubtracted jet
173     AliEmcalJet *jet_sub = new ((*fJetsSub)[jetCount])
174       AliEmcalJet(jets_sub[ijet].perp(), jets_sub[ijet].eta(), jets_sub[ijet].phi(), jets_sub[ijet].m());
175     jet_sub->SetLabel(ijet);
176
177     fastjet::PseudoJet area(fjw.GetJetAreaVector(ijet));
178     jet_sub->SetArea(area.perp());
179     jet_sub->SetAreaEta(area.eta());
180     jet_sub->SetAreaPhi(area.phi());
181     jet_sub->SetAreaEmc(area.perp());
182
183     // Fill constituent info
184     std::vector<fastjet::PseudoJet> constituents_unsub(fjw.GetJetConstituents(ijet));
185     std::vector<fastjet::PseudoJet> constituents_sub = jets_sub[ijet].constituents();
186     jet_sub->SetNumberOfTracks(constituents_sub.size());
187     fJetTask->FillJetConstituents(jet_sub, constituents_sub, fJetTask->GetTracks(), fJetTask->GetClusters(), constituents_unsub, 1, fParticlesSub);
188
189     jetCount++;
190   }
191
192 #endif
193
194 }
195