]>
Commit | Line | Data |
---|---|---|
578adbef | 1 | // |
48924b8b | 2 | // Class to select particles in MC events. |
578adbef | 3 | // |
4 | // Author: S. Aiola | |
5 | ||
6 | #include "AliEmcalMCTrackSelector.h" | |
7 | ||
8 | #include <TClonesArray.h> | |
9 | ||
578adbef | 10 | #include "AliVEvent.h" |
11 | #include "AliMCEvent.h" | |
09230f47 | 12 | #include "AliAODMCParticle.h" |
13 | #include "AliMCParticle.h" | |
48924b8b | 14 | #include "AliStack.h" |
15 | #include "AliNamedArrayI.h" | |
16 | ||
578adbef | 17 | #include "AliLog.h" |
18 | ||
19 | ClassImp(AliEmcalMCTrackSelector) | |
20 | ||
21 | //________________________________________________________________________ | |
22 | AliEmcalMCTrackSelector::AliEmcalMCTrackSelector() : | |
23 | AliAnalysisTaskSE("AliEmcalMCTrackSelector"), | |
48924b8b | 24 | fParticlesOutName("MCParticlesSelected"), |
25 | fOnlyPhysPrim(kTRUE), | |
578adbef | 26 | fRejectNK(kFALSE), |
27 | fChargedMC(kFALSE), | |
48924b8b | 28 | fOnlyHIJING(kFALSE), |
df16061d | 29 | fEtaMax(1), |
48924b8b | 30 | fParticlesMapName(""), |
df16061d | 31 | fInit(kFALSE), |
48924b8b | 32 | fParticlesIn(0), |
33 | fParticlesOut(0), | |
34 | fParticlesMap(0), | |
35 | fEvent(0), | |
36 | fMC(0), | |
30b85b3c | 37 | fIsESD(kFALSE), |
38 | fDisabled(kFALSE) | |
578adbef | 39 | { |
40 | // Constructor. | |
41 | } | |
42 | ||
43 | //________________________________________________________________________ | |
44 | AliEmcalMCTrackSelector::AliEmcalMCTrackSelector(const char *name) : | |
45 | AliAnalysisTaskSE(name), | |
48924b8b | 46 | fParticlesOutName("MCParticlesSelected"), |
47 | fOnlyPhysPrim(kTRUE), | |
578adbef | 48 | fRejectNK(kFALSE), |
49 | fChargedMC(kFALSE), | |
48924b8b | 50 | fOnlyHIJING(kFALSE), |
df16061d | 51 | fEtaMax(1), |
48924b8b | 52 | fParticlesMapName(""), |
df16061d | 53 | fInit(kFALSE), |
48924b8b | 54 | fParticlesIn(0), |
55 | fParticlesOut(0), | |
56 | fParticlesMap(0), | |
57 | fEvent(0), | |
58 | fMC(0), | |
30b85b3c | 59 | fIsESD(kFALSE), |
60 | fDisabled(kFALSE) | |
578adbef | 61 | { |
62 | // Constructor. | |
63 | } | |
64 | ||
65 | //________________________________________________________________________ | |
66 | AliEmcalMCTrackSelector::~AliEmcalMCTrackSelector() | |
67 | { | |
68 | // Destructor. | |
69 | } | |
70 | ||
71 | //________________________________________________________________________ | |
72 | void AliEmcalMCTrackSelector::UserCreateOutputObjects() | |
73 | { | |
74 | // Create my user objects. | |
578adbef | 75 | } |
76 | ||
77 | //________________________________________________________________________ | |
78 | void AliEmcalMCTrackSelector::UserExec(Option_t *) | |
79 | { | |
80 | // Main loop, called for each event. | |
578adbef | 81 | |
30b85b3c | 82 | if (fDisabled) return; |
83 | ||
1f12855f | 84 | if (!fInit) { |
48924b8b | 85 | fEvent = InputEvent(); |
86 | if (!fEvent) { | |
87 | AliError("Could not retrieve event! Returning"); | |
88 | return; | |
89 | } | |
90 | ||
91 | if (fEvent->InheritsFrom("AliESDEvent")) fIsESD = kTRUE; | |
92 | else fIsESD = kFALSE; | |
93 | ||
94 | TObject *obj = fEvent->FindListObject(fParticlesOutName); | |
95 | if (obj) { // the output array is already present in the array! | |
4f280f6b | 96 | AliError(Form("The output array %s is already present in the event! Task will be disabled.", fParticlesOutName.Data())); |
30b85b3c | 97 | fDisabled = kTRUE; |
48924b8b | 98 | return; |
99 | } | |
100 | else { // copy the array from the standard ESD/AOD collections, and filter if requested | |
101 | ||
102 | fParticlesOut = new TClonesArray("AliAODMCParticle"); // the output will always be of AliAODMCParticle, regardless of the input | |
103 | fParticlesOut->SetName(fParticlesOutName); | |
104 | fEvent->AddObject(fParticlesOut); | |
105 | ||
106 | fParticlesMapName = fParticlesOutName; | |
107 | fParticlesMapName += "_Map"; | |
4f280f6b | 108 | |
109 | if (fEvent->FindListObject(fParticlesMapName)) { | |
110 | AliError(Form("The output array map %s is already present in the event! Task will be disabled.", fParticlesMapName.Data())); | |
111 | fDisabled = kTRUE; | |
112 | return; | |
113 | } | |
114 | else { | |
115 | fParticlesMap = new AliNamedArrayI(fParticlesMapName, 99999); | |
116 | fEvent->AddObject(fParticlesMap); | |
117 | } | |
118 | ||
48924b8b | 119 | if (!fIsESD) { |
120 | fParticlesIn = static_cast<TClonesArray*>(InputEvent()->FindListObject(AliAODMCParticle::StdBranchName())); | |
121 | if (!fParticlesIn) { | |
30b85b3c | 122 | AliError("Could not retrieve AOD MC particles! Task will be disabled."); |
123 | fDisabled = kTRUE; | |
48924b8b | 124 | return; |
125 | } | |
126 | TClass *cl = fParticlesIn->GetClass(); | |
127 | if (!cl->GetBaseClass("AliAODMCParticle")) { | |
30b85b3c | 128 | AliError(Form("%s: Collection %s does not contain AliAODMCParticle! Task will be disabled.", GetName(), AliAODMCParticle::StdBranchName())); |
129 | fDisabled = kTRUE; | |
48924b8b | 130 | fParticlesIn = 0; |
131 | return; | |
132 | } | |
09230f47 | 133 | } |
134 | } | |
1f12855f | 135 | |
48924b8b | 136 | fMC = MCEvent(); |
137 | if (!fMC) { | |
30b85b3c | 138 | AliError("Could not retrieve MC event! Returning"); |
139 | fDisabled = kTRUE; | |
48924b8b | 140 | return; |
141 | } | |
142 | ||
1f12855f | 143 | fInit = kTRUE; |
578adbef | 144 | } |
145 | ||
48924b8b | 146 | if (fIsESD) ConvertMCParticles(); |
147 | else CopyMCParticles(); | |
148 | } | |
149 | ||
150 | //________________________________________________________________________ | |
151 | void AliEmcalMCTrackSelector::ConvertMCParticles() | |
152 | { | |
153 | // Convert MC particles in MC AOD particles. | |
154 | ||
578adbef | 155 | // clear container (normally a null operation as the event should clean it already) |
48924b8b | 156 | fParticlesOut->Delete(); |
7f76e479 | 157 | |
48924b8b | 158 | // clear particles map |
159 | fParticlesMap->Clear(); | |
7f76e479 | 160 | |
48924b8b | 161 | const Int_t Nparticles = fMC->GetNumberOfTracks(); |
162 | const Int_t nprim = fMC->GetNumberOfPrimaries(); | |
578adbef | 163 | |
48924b8b | 164 | if (fParticlesMap->GetSize() <= Nparticles) fParticlesMap->Set(Nparticles*2); |
cac0e10b | 165 | |
48924b8b | 166 | // loop over particles |
167 | for (Int_t iPart = 0, nacc = 0; iPart < Nparticles; iPart++) { | |
1f12855f | 168 | |
4f280f6b | 169 | fParticlesMap->AddAt(-1, iPart); |
170 | ||
48924b8b | 171 | AliMCParticle* part = static_cast<AliMCParticle*>(fMC->GetTrack(iPart)); |
578adbef | 172 | |
48924b8b | 173 | if (!part) continue; |
578adbef | 174 | |
48924b8b | 175 | if (fEtaMax > 0. && TMath::Abs(part->Eta()) > fEtaMax) continue; |
578adbef | 176 | |
48924b8b | 177 | if (fRejectNK && (part->PdgCode() == 130 || part->PdgCode() == 2112)) continue; |
578adbef | 178 | |
48924b8b | 179 | if (fChargedMC && part->Charge() == 0) continue; |
180 | ||
181 | Int_t genIndex = part->GetGeneratorIndex(); | |
182 | if (fOnlyHIJING && genIndex != 0) continue; | |
1f12855f | 183 | |
48924b8b | 184 | Bool_t isPhysPrim = fMC->IsPhysicalPrimary(iPart); |
185 | if (fOnlyPhysPrim && !isPhysPrim) continue; | |
09230f47 | 186 | |
48924b8b | 187 | fParticlesMap->AddAt(nacc, iPart); |
188 | ||
189 | Int_t flag = 0; | |
190 | if (iPart < nprim) flag |= AliAODMCParticle::kPrimary; | |
191 | if (isPhysPrim) flag |= AliAODMCParticle::kPhysicalPrim; | |
192 | if (fMC->IsSecondaryFromWeakDecay(iPart)) flag |= AliAODMCParticle::kSecondaryFromWeakDecay; | |
193 | if (fMC->IsSecondaryFromMaterial(iPart)) flag |= AliAODMCParticle::kSecondaryFromMaterial; | |
194 | ||
195 | AliAODMCParticle *aodPart = new ((*fParticlesOut)[nacc]) AliAODMCParticle(part, iPart, flag); | |
196 | aodPart->SetGeneratorIndex(genIndex); | |
197 | aodPart->SetStatus(part->Particle()->GetStatusCode()); | |
198 | aodPart->SetMCProcessCode(part->Particle()->GetUniqueID()); | |
1f12855f | 199 | |
48924b8b | 200 | nacc++; |
578adbef | 201 | } |
202 | } | |
09230f47 | 203 | |
204 | //________________________________________________________________________ | |
48924b8b | 205 | void AliEmcalMCTrackSelector::CopyMCParticles() |
09230f47 | 206 | { |
48924b8b | 207 | // Convert standard MC AOD particles in a new array, and filter if requested. |
09230f47 | 208 | |
48924b8b | 209 | if (!fParticlesIn) return; |
09230f47 | 210 | |
48924b8b | 211 | // clear container (normally a null operation as the event should clean it already) |
212 | fParticlesOut->Delete(); | |
213 | ||
214 | // clear particles map | |
215 | fParticlesMap->Clear(); | |
216 | ||
217 | const Int_t Nparticles = fParticlesIn->GetEntriesFast(); | |
218 | ||
1b2c4ff7 | 219 | if (fParticlesMap->GetSize() <= Nparticles) fParticlesMap->Set(Nparticles*2); |
220 | ||
48924b8b | 221 | // loop over particles |
222 | for (Int_t iPart = 0, nacc = 0; iPart < Nparticles; iPart++) { | |
223 | ||
224 | AliAODMCParticle* part = static_cast<AliAODMCParticle*>(fParticlesIn->At(iPart)); | |
225 | ||
aa0cd389 | 226 | fParticlesMap->AddAt(-1, iPart); |
227 | ||
48924b8b | 228 | if (!part) continue; |
229 | ||
230 | if (fEtaMax > 0. && TMath::Abs(part->Eta()) > fEtaMax) continue; | |
09230f47 | 231 | |
48924b8b | 232 | if (fRejectNK && (part->PdgCode() == 130 || part->PdgCode() == 2112)) continue; |
233 | ||
234 | if (fChargedMC && part->Charge() == 0) continue; | |
09230f47 | 235 | |
48924b8b | 236 | if (fOnlyHIJING && (part->GetGeneratorIndex() != 0)) continue; |
237 | ||
238 | if (fOnlyPhysPrim && !part->IsPhysicalPrimary()) continue; | |
239 | ||
240 | fParticlesMap->AddAt(nacc, iPart); | |
241 | ||
85b82ddd | 242 | AliAODMCParticle *newPart = new ((*fParticlesOut)[nacc]) AliAODMCParticle(*part); |
243 | newPart->SetGeneratorIndex(part->GetGeneratorIndex()); | |
48924b8b | 244 | |
245 | nacc++; | |
09230f47 | 246 | } |
247 | } |