AliPhysics  e6c8d43 (e6c8d43)
AliAnalysisTaskK0toPi0Pi0.cxx
Go to the documentation of this file.
1 /**************************************************************************************
2  * Copyright (C) 2017, Copyright Holders of the ALICE Collaboration *
3  * All rights reserved. *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions are met: *
7  * * Redistributions of source code must retain the above copyright *
8  * notice, this list of conditions and the following disclaimer. *
9  * * Redistributions in binary form must reproduce the above copyright *
10  * notice, this list of conditions and the following disclaimer in the *
11  * documentation and/or other materials provided with the distribution. *
12  * * Neither the name of the <organization> nor the *
13  * names of its contributors may be used to endorse or promote products *
14  * derived from this software without specific prior written permission. *
15  * *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
19  * DISCLAIMED. IN NO EVENT SHALL ALICE COLLABORATION BE LIABLE FOR ANY *
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
26  **************************************************************************************/
27 #include <array>
28 
29 #include <THistManager.h>
30 #include <TLinearBinning.h>
31 #include <TList.h>
32 #include <TString.h>
34 #include "AliAODConversionMother.h"
35 #include "AliAODConversionPhoton.h"
36 #include "AliCaloPhotonCuts.h"
37 #include "AliClusterContainer.h"
39 #include "AliConversionMesonCuts.h"
40 #include "AliConvEventCuts.h"
41 #include "AliLog.h"
42 #include "AliVCluster.h"
43 #include "AliV0ReaderV1.h"
45 
49 
52  fLocalInitialized(kFALSE),
53  fCurrentRun(-1),
54  fNewFile(kFALSE),
55  fV0Reader(nullptr),
56  fV0ReaderName("V0ReaderV1"),
57  fClusterContainer(nullptr),
58  fIsMC(false),
59  fWeightJetJetMC(1.),
60  fEventPlaneAngle(0.),
61  fEventCuts(nullptr),
62  fConvPhotonCuts(nullptr),
63  fCaloPhotonCuts(nullptr),
64  fPi0CutsConvConv(nullptr),
65  fPi0CutsCaloCalo(nullptr),
66  fPi0CutsConvCalo(nullptr),
67  fK0Cuts(nullptr),
68  fSamePCMHandler(nullptr),
69  fSameEMCALHandler(nullptr),
70  fMixedHandler(nullptr),
71  fHistos(nullptr),
72  fOutput(nullptr)
73 {
74 
75 }
76 
78  AliAnalysisTaskSE(name),
79  fLocalInitialized(kFALSE),
80  fCurrentRun(-1),
81  fNewFile(kFALSE),
82  fV0Reader(nullptr),
83  fV0ReaderName("V0ReaderV1"),
84  fClusterContainer(nullptr),
85  fIsMC(false),
86  fWeightJetJetMC(1.),
87  fEventPlaneAngle(0),
88  fEventCuts(nullptr),
89  fConvPhotonCuts(nullptr),
90  fCaloPhotonCuts(nullptr),
91  fPi0CutsConvConv(nullptr),
92  fPi0CutsCaloCalo(nullptr),
93  fPi0CutsConvCalo(nullptr),
94  fK0Cuts(nullptr),
95  fSamePCMHandler(nullptr),
96  fSameEMCALHandler(nullptr),
97  fMixedHandler(nullptr),
98  fHistos(nullptr),
99  fOutput(nullptr)
100 {
101  DefineOutput(1, TList::Class());
102 }
103 
104 
105 
107  if(fHistos) delete fHistos;
108 }
109 
110 //=================================== CREATE OUTPUT OBJECTS ====================================================================
112  fOutput = new TList();
113  fOutput->SetOwner(kTRUE);
114 
115  // Define the different types of binnings
116  TLinearBinning massBinningK0(800, 0.0, 0.8),massBinningPi0(500, 0., 0.5), ptBinning(300, 0.3, 30.), openingAngleBinning(100, 0., 1.), candidateBinning( 101, -0.5, 100.5), alphaBinning(200, -1., 1.);
117 
118 
119 
120  // Connecting input V0 reader
121  fV0Reader=dynamic_cast<AliV0ReaderV1*>(AliAnalysisManager::GetAnalysisManager()->GetTask(fV0ReaderName.Data()));
122  if(!fV0Reader){
123  AliFatal("Error: No V0 Reader");
124  }// GetV0Reader
125 
129  // Define histograms
130  fHistos = new THistManager("K0stoPi0Pi0");
131 
132  AliDebug(2, "************* Defining Event Counter Histograms ********************");
133 
134 
135  // Event counter histograms
136  fHistos->CreateTH1("hEventQualityBefore", "V0 reader Event Quality (0 = good)", 13, -0.5, 12.5);
137  fHistos->CreateTH1("hEventQualityAfter", "V0 reader Event Quality (0 = good)", 13, -0.5, 12.5);
138  fHistos->CreateTH1("hEventSelectionStatusBefore", "Event selection status (0 = good)", 14, -0.5, 13.5);
139  fHistos->CreateTH1("hEventSelectionStatusAfter", "Event selection status (0 = good)", 14, -0.5, 13.5 );
140  fHistos->CreateTH1("hVertexZ", "z-component of the primary vertex; z (cm); Number of events", 1000, -40., 40.);
141  fHistos->CreateTH1("hCaloPhotonsBefore", "Number of Events", 13, -0.5, 12.5);
142  fHistos->CreateTH1("hCaloPhotonsAfter", "Number of Events", 13, -0.5, 12.5);
143  fHistos->CreateTH1("hConvPhotonsBefore", "Number of Events", 13, -0.5, 12.5);
144  fHistos->CreateTH1("hConvPhotonsAfter", "Number of Events", 13, -0.5, 12.5);
145 
146  AliDebug(2, "************* Defining Photon QA Histograms ********************");
147 
148  // Photon QA
149  fHistos->CreateTH1("hCaloPhotonPt", "p_{t}-distribution of the conversion photons; p_{t} (GeV); Yield", ptBinning);
150  fHistos->CreateTH1("hConvPhotonPt", "p_{t}-distribution of the conversion photons; p_{t} (GeV); Yield", ptBinning);
151  fHistos->CreateTH2("hConvPhotonEtaR", "#eta vs conversion radius of conversion photons; #eta; R (cm)", 200, -1.5, 1.5, 300, 0., 300);
152 
153  AliDebug(2, "************* Defining Pi0 Histograms ********************");
154 
155  // create plots for Pi0 invariant mass, alpha and opening angle distributions for Before, After, BKG
156  const std::array<TString, 3> pi0rec = {"ConvConv", "ConvCalo", "CaloCalo"}; // aka PCM, EMCAL, PCM-EMCAL
157  for(const auto &reccase : pi0rec){
158 
159  // for candidates in a wide mass region
160  fHistos->CreateTH1("hNPi0CandidatesPerEventBefore" + reccase, "Number of pi0 candidates in event before selection",candidateBinning);
161  fHistos->CreateTH2("hMassvsPtPi0Before" + reccase + "All", "inv. mass vs. p_{t} for all #pi^{0} (" + reccase + ") candidates; inv. mass (GeV/c^{2}); p_{t} (GeV/c)", massBinningPi0, ptBinning);
162  // only for candidates in the pi0 mass region
163  fHistos->CreateTH2("hMassvsPtPi0Before" + reccase + "Sel", "inv. mass vs. p_{t} for selected #pi^{0} (" + reccase + ") candidates; inv. mass (GeV/c^{2}); p_{t} (GeV/c)", massBinningPi0, ptBinning);
164  fHistos->CreateTH2("hAlphavsPtPi0Before" + reccase, "#alpha vs p_{t} for selected #p^i{0} (" + reccase + ") candidates; #alpha; p_{t}", alphaBinning, ptBinning);
165  fHistos->CreateTH2("hOpeningAnglevsPtPi0Before" + reccase, "Opening angle vs. p_{t} for selected #pi^{0} (" + reccase + ") candidates; opening angle; p_{t} (GeV/c)", openingAngleBinning, ptBinning);
166 
167  fHistos->CreateTH1("hPi0Selection" + reccase, "Pi0 selection status bit for reconstruction case " + reccase, 2, -0.5, 1.5);
168  // after selection
169  fHistos->CreateTH1("hNPi0CandidatesPerEventAfter" + reccase, "Number of pi0 candidates in event before selection", candidateBinning);
170  fHistos->CreateTH2("hMassvsPtPi0After" + reccase + "All", "inv. mass vs. p_{t} for all #pi^{0} (" + reccase + ") candidates; inv. mass (GeV/c^{2}); p_{t} (GeV/c)", massBinningPi0, ptBinning);
171 
172  // only for candidates in the pi0 mass region
173  fHistos->CreateTH2("hMassvsPtPi0After" + reccase + "Sel", "inv. mass vs. p_{t} for selected #pi^{0} (" + reccase + ") candidates; inv. mass (GeV/c^{2}); p_{t} (GeV/c)", massBinningPi0, ptBinning);
174  fHistos->CreateTH2("hAlphavsPtPi0After" + reccase, "#alpha vs p_{t} for selected #p^i{0} (" + reccase + ") candidates; #alpha; p_{t}", alphaBinning, ptBinning);
175  fHistos->CreateTH2("hOpeningAnglevsPtPi0After" + reccase, "Opening angle vs. p_{t} for selected #pi^{0} (" + reccase + ") candidates; opening angle; p_{t} (GeV/c)", openingAngleBinning, ptBinning);
176 
177  }
178 
179  AliDebug(2, "************* Defining K0 Histograms ********************");
180 
181  // K0short invariant mass distribution and opening angle distributions
182  const std::array<TString, 6> k0Shortrec = {"AllConv", "AllCalo", "DiffMixed", "SameMixed", "ConvoCalo","CaloConvo" }; // aka 6 cases
183  for(const auto &reccase1 : k0Shortrec){
184  // before selection
185  fHistos->CreateTH1("hNK0CandidatesPerEventBefore" + reccase1, "Number of K0 candidates in event before selection", candidateBinning);
186  fHistos->CreateTH2("hMassvsPtK0ShortBefore" + reccase1, "inv. mass vs. p_{t} for #k^{0}s (" + reccase1 + ") candidates; inv. mass (GeV/c^{2}); p_{t} (GeV/c)", massBinningK0, ptBinning);
187  fHistos->CreateTH2("hOpeningAnglevsPtK0ShortBefore"+ reccase1, "Opening angle vs. p_{t} for k0Short (" + reccase1 + ") candidates; opening angle; p_{t} (GeV/c)", openingAngleBinning, ptBinning);
188 
189  fHistos->CreateTH1("hK0Selection" + reccase1, "Pi0 selection status bit for reconstruction case " + reccase1, 2, -0.5, 1.5);
190 
191  // after selection
192  fHistos->CreateTH1("hNK0CandidatesPerEventAfter" + reccase1, "Number of K0 candidates in event after selection", candidateBinning);
193  fHistos->CreateTH2("hMassvsPtK0ShortAfter" + reccase1, "Inv. mass vs. p_{t} for #k^{0}s (" + reccase1 + ") candidates; inv. mass (GeV/c^{2}); p_{t} (GeV/c)", massBinningK0, ptBinning);
194  fHistos->CreateTH2("hOpeningAnglevsPtK0ShortAfter"+ reccase1, "Opening angle vs. p_{t} for k0Short (" + reccase1 + ") candidates; opening angle; p_{t} (GeV/c)", openingAngleBinning, ptBinning);
195 
196 
197  //background histograms
198  fHistos->CreateTH2("hMassvsPtK0ShortBKG" + reccase1, " Background: Inv. mass vs. p_{t} for #k^{0}s (" + reccase1 + ") candidates; inv. mass (GeV/c^{2}); p_{t} (GeV/c)", massBinningK0, ptBinning);
199  fHistos->CreateTH2("hOpeningAnglevsPtK0ShortBKG"+ reccase1, "Background: Opening angle vs. p_{t} for k0Short (" + reccase1 + ") candidates; opening angle; p_{t} (GeV/c)", openingAngleBinning, ptBinning);
200 
201  }
202 
203  for(auto hist : *(fHistos->GetListOfHistograms())) fOutput->Add(hist);
204 
205  // Adding cut QA
206  TList *qaV0reader = new TList;
207  qaV0reader->SetName("QA_V0reader");
208  qaV0reader->SetOwner(kTRUE);
209  qaV0reader->Add(fV0Reader->GetEventCutHistograms());
210  qaV0reader->Add(fV0Reader->GetCutHistograms());
211  fOutput->Add(qaV0reader);
212 
213  // Adding to QA histos to the output - change name in order to
214  // better identify the histos
218  TList *histlist = fPi0CutsConvConv->GetCutHistograms();
219  TString histname = "Pi0CutsConvConv_" + TString(histlist->GetName());
220  histlist->SetName(histname);
221  fOutput->Add(histlist);
222  histlist = fPi0CutsCaloCalo->GetCutHistograms();
223  histname = "Pi0CutsCalo_" + TString(histlist->GetName());
224  histlist->SetName(histname);
225  fOutput->Add(histlist);
226  histlist = fPi0CutsConvCalo->GetCutHistograms();
227  histname = "Pi0CutsConvCalo_" + TString(histlist->GetName());
228  histlist->SetName(histname);
229  fOutput->Add(histlist);
230  histlist = fK0Cuts->GetCutHistograms();
231  histname = "K0cuts_" + TString(histlist->GetName());
232  histlist->SetName(histname);
233  fOutput->Add(histlist);
234 
235 
236  PostData(1, fOutput);
237 
238 }
239 
240 //=================================== EXEC ONCE ====================================================================
242  if(!fClusterContainer) fClusterContainer = new AliClusterContainer(fInputEvent->IsA() == AliESDEvent::Class() ? "CaloClusters" : "caloClusters");
243  fClusterContainer->SetArray(fInputEvent);
244 
245  if(fConvPhotonCuts){
247  }
248 
249 }
250 
251 //=================================== USER EXEC ====================================================================
253  if(!fLocalInitialized) {
254  ExecOnce();
255  fLocalInitialized = kTRUE;
256  }
257 
258  if(fCurrentRun != fInputEvent->GetRunNumber()) {
259  RunChanged();
260  fCurrentRun = fInputEvent->GetRunNumber();
261  }
262 
263 
264  // do event selection
265  // Use the same event selection as for the v0 reader
266  // Good events defined as events with event quality 0
267  Int_t selectionStatus = fEventCuts->IsEventAcceptedByCut(fV0Reader->GetEventCuts(), fInputEvent, fMCEvent, false, false);
268  Int_t eventQuality = fV0Reader->GetEventCuts()->GetEventQuality();
269  fHistos->FillTH1("hEventQualityBefore", eventQuality);
270  fHistos->FillTH1("hEventSelectionStatusBefore", selectionStatus);
271  if(selectionStatus || eventQuality) return;
272  fHistos->FillTH1("hEventQualityAfter", eventQuality);
273  fHistos->FillTH1("hEventSelectionStatusAfter", selectionStatus);
274  fHistos->FillTH1("hVertexZ", fInputEvent->GetPrimaryVertex()->GetZ());
275 
276 
277  // get Photon candidates
278  fHistos->FillTH1("hConvPhotonsBefore",fV0Reader->GetNReconstructedGammas());
279  std::vector<AliAODConversionPhoton> conversionPhotons = MakeConversionPhotonCandidates(*fV0Reader, *fConvPhotonCuts);
280  MakePhotonQAConv(conversionPhotons, *fEventCuts);
281  Int_t numPhotons = conversionPhotons.size();
282  fHistos->FillTH1("hConvPhotonsAfter", numPhotons);
283 
284  fHistos->FillTH1("hCaloPhotonsBefore",fClusterContainer->GetNEntries());
285  std::vector<AliAODConversionPhoton> caloPhotons = MakeCaloPhotonCandidates(*fClusterContainer, *fCaloPhotonCuts);
286  MakePhotonQACalo(caloPhotons, *fEventCuts);
287  Int_t numCaloPhotons = caloPhotons.size();
288  fHistos->FillTH1("hCaloPhotonsAfter", numCaloPhotons);
289 
290  AliDebug(2,"************************** Initializing Pi0 candidates *************************\n" );
291 
292  // get Pi0 candidates
293  std::vector<AliAODConversionMother> samePi0PCM = MakePi0Candidates(&conversionPhotons, nullptr, *fPi0CutsConvConv),
294  samePi0EMCAL = MakePi0Candidates(&caloPhotons, nullptr, *fPi0CutsCaloCalo),
295  mixedPi0 = MakePi0Candidates(&conversionPhotons, &caloPhotons, *fPi0CutsConvCalo);
296 
297  // create the BG Handlers
298 
299 
300  Int_t binZ = fSamePCMHandler->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
302 
303 
304 // Int_t nEventsSamePCM = fSamePCMHandler->GetNBackgroundEventsInBuffer(binZ,mbin);
305 // Int_t nEventsSameEMCAL = fSameEMCALHandler->GetNBackgroundEventsInBuffer(binZ,mbin);
306 // Int_t nEventsMixed = fMixedHandler->GetNBackgroundEventsInBuffer(binZ,mbin);
307  //printf("Zbin is %d\n",binZ );
308  //printf("multiplicityBin is %d\n", mbin);
309  //printf("nEventsSamePCM: %d ::: nEventsSameEMCAL %d ::: nEventsMixed %d\n", nEventsSamePCM,nEventsSameEMCAL,nEventsMixed);
310 // std::vector<AliAODConversionMother> samePi0PCM_BG;
311 // std::vector<AliAODConversionMother> samePi0EMCAL_BG;
312 // std::vector<AliAODConversionMother> mixedPi0_BG;
313 
314 
315  Double_t primVtxX = fInputEvent->GetPrimaryVertex()->GetX();
316  Double_t primVtxY = fInputEvent->GetPrimaryVertex()->GetY();
317  Double_t primVtxZ = fInputEvent->GetPrimaryVertex()->GetZ();
318 
319 
320 
321  // fill the QA histograms before selection
322  AliDebug(1, "New event - make Pi0 candidates");
323  MakePi0QA(samePi0PCM, "ConvConv", "Before");
324  MakePi0QA(samePi0EMCAL, "CaloCalo", "Before");
325  MakePi0QA(mixedPi0, "ConvCalo", "Before");
326  AliDebug(1, "New event - finished pi0 candidates");
327 
328 
329  //make the selections
330  std::vector<AliAODConversionMother> samePi0PCMSelection = SelectMeson(samePi0PCM, *fPi0CutsConvConv, kPi0, "ConvConv");
331  std::vector<AliAODConversionMother> samePi0EMCALSelection = SelectMeson(samePi0EMCAL, *fPi0CutsCaloCalo, kPi0, "CaloCalo");
332  std::vector<AliAODConversionMother> mixedPi0Selection = SelectMeson(mixedPi0, *fPi0CutsConvCalo, kPi0, "ConvCalo");
333 
334  // Additionally fill the QA histograms after the selection
335  MakePi0QA(samePi0PCMSelection, "ConvConv", "After");
336  MakePi0QA(samePi0EMCALSelection, "CaloCalo", "After");
337  MakePi0QA(mixedPi0Selection, "ConvCalo", "After");
338 
339 
340  // now that we have the backgrounds, time to mix them
341  // have to do this for each handler
342 
343 
344  for(int k =0 ; k< fSamePCMHandler->GetNBGEvents(); k++){
345  MakeK0ShortQA(MakeK0ShortCandidatesMixed(&samePi0PCMSelection,fSamePCMHandler->GetBGGoodMesons(binZ,mbin,k),*fK0Cuts), "AllConv", "BKG");
346  MakeK0ShortQA(MakeK0ShortCandidatesMixed(&samePi0EMCALSelection,fSamePCMHandler->GetBGGoodMesons(binZ,mbin,k),*fK0Cuts), "SameMixed", "BKG");
347  MakeK0ShortQA(MakeK0ShortCandidatesMixed(&mixedPi0Selection,fSamePCMHandler->GetBGGoodMesons(binZ,mbin,k),*fK0Cuts), "ConvoCalo", "BKG");
348  }
349 
350  for(int g = 0; g < fSameEMCALHandler->GetNBGEvents(); g++){
351  MakeK0ShortQA(MakeK0ShortCandidatesMixed(&samePi0PCMSelection,fSameEMCALHandler->GetBGGoodMesons(binZ,mbin,g),*fK0Cuts),"SameMixed", "BKG" );
352  MakeK0ShortQA(MakeK0ShortCandidatesMixed(&samePi0EMCALSelection,fSameEMCALHandler->GetBGGoodMesons(binZ,mbin,g),*fK0Cuts),"AllCalo", "BKG" );
353  MakeK0ShortQA(MakeK0ShortCandidatesMixed(&mixedPi0Selection,fSameEMCALHandler->GetBGGoodMesons(binZ,mbin,g),*fK0Cuts),"CaloConvo", "BKG" );
354  }
355 
356  for(int q = 0; q < fMixedHandler->GetNBGEvents(); q++){
357  MakeK0ShortQA(MakeK0ShortCandidatesMixed(&samePi0PCMSelection,fMixedHandler->GetBGGoodMesons(binZ,mbin,q),*fK0Cuts),"ConvoCalo", "BKG" );
358  MakeK0ShortQA(MakeK0ShortCandidatesMixed(&samePi0EMCALSelection,fMixedHandler->GetBGGoodMesons(binZ,mbin,q),*fK0Cuts),"CaloConvo", "BKG" );
359  MakeK0ShortQA(MakeK0ShortCandidatesMixed(&mixedPi0Selection,fMixedHandler->GetBGGoodMesons(binZ,mbin,q),*fK0Cuts),"DiffMixed", "BKG" );
360  }
361 
362  // get K0Short candidates
363  std::vector<AliAODConversionMother> allPCM = MakeK0ShortCandidates(&samePi0PCMSelection, nullptr, *fK0Cuts);
364  std::vector<AliAODConversionMother> allEMC = MakeK0ShortCandidates(&samePi0EMCALSelection, nullptr, *fK0Cuts);
365  std::vector<AliAODConversionMother> PCMEMC = MakeK0ShortCandidates(&samePi0PCMSelection, &mixedPi0Selection, *fK0Cuts);
366  std::vector<AliAODConversionMother> EMCPCM = MakeK0ShortCandidates(&samePi0EMCALSelection, &mixedPi0Selection, *fK0Cuts);
367  std::vector<AliAODConversionMother> mixedSame = MakeK0ShortCandidates(&samePi0EMCALSelection, &samePi0PCMSelection, *fK0Cuts);
368  std::vector<AliAODConversionMother> mixedDiff = MakeK0ShortCandidates(&mixedPi0Selection, nullptr, *fK0Cuts);
369 
370 
371 
372  // fill the QA histograms prior to selection
373  MakeK0ShortQA(allPCM, "AllConv", "Before");
374  MakeK0ShortQA(allEMC,"AllCalo", "Before");
375  MakeK0ShortQA(PCMEMC,"ConvoCalo", "Before");
376  MakeK0ShortQA(EMCPCM,"CaloConvo", "Before");
377  MakeK0ShortQA(mixedSame, "SameMixed", "Before");
378  MakeK0ShortQA(mixedDiff, "DiffMixed", "Before");
379 
380  // make the selections
381  std::vector<AliAODConversionMother> allPCMSelection = SelectMeson(allPCM, *fK0Cuts, kK0, "AllConv");
382  std::vector<AliAODConversionMother> allEMCSelection = SelectMeson(allEMC, *fK0Cuts, kK0, "AllCalo");
383  std::vector<AliAODConversionMother> PCMEMCSelection = SelectMeson(PCMEMC, *fK0Cuts, kK0, "ConvoCalo");
384  std::vector<AliAODConversionMother> EMCPCMSelection = SelectMeson(EMCPCM,*fK0Cuts, kK0, "CaloConvo");
385  std::vector<AliAODConversionMother> mixedSameSelection = SelectMeson(mixedSame, *fK0Cuts, kK0, "SameMixed");
386  std::vector<AliAODConversionMother> mixedDiffSelection = SelectMeson(mixedDiff, *fK0Cuts, kK0, "DiffMixed");
387 
388  // fill the QA histograms after selection
389  MakeK0ShortQA(allPCMSelection, "AllConv", "After");
390  MakeK0ShortQA(allEMCSelection,"AllCalo", "After");
391  MakeK0ShortQA(PCMEMCSelection,"ConvoCalo", "After");
392  MakeK0ShortQA(EMCPCMSelection,"CaloConvo", "After");
393  MakeK0ShortQA(mixedSameSelection, "SameMixed", "After");
394  MakeK0ShortQA(mixedDiffSelection, "DiffMixed", "After");
395 
396  if(samePi0PCMSelection.size() ){
397  fSamePCMHandler->AddMesonEvent(samePi0PCMSelection, primVtxX, primVtxY , primVtxZ,mbin);
398  //printf("*************************** nEventsSamePCMAfterAdding: %d \n", nEventsSamePCM);
399  }
400  if (samePi0EMCALSelection.size()){
401  fSameEMCALHandler->AddMesonEvent(samePi0EMCALSelection,primVtxX,primVtxY,primVtxZ,mbin);
402  //printf("***************************** nEventsSameEMCALAfterAdding %d \n", nEventsSameEMCAL);
403  }
404  if(mixedPi0Selection.size()){
405  fMixedHandler->AddMesonEvent(mixedPi0Selection,primVtxX,primVtxY,primVtxZ,mbin);
406  //printf("****************************** nEventsMixedAfterAdding %d\n", nEventsMixed);
407  }
408 
409 
410 
411  PostData(1, fOutput);
412 }
413 
414 
415 //=================================== MAKE CALO PHOTON CANDIDATES ====================================================================
416 std::vector<AliAODConversionPhoton> AliAnalysisTaskK0toPi0Pi0::MakeCaloPhotonCandidates(const AliClusterContainer &inputcont, AliCaloPhotonCuts &cuts){
417  std::vector<AliAODConversionPhoton> candidates;
418  cuts.FillHistogramsExtendedQA(fInputEvent, fIsMC);
419 
420  // vertex
421  Double_t vertex[3] = {0,0,0};
422  InputEvent()->GetPrimaryVertex()->GetXYZ(vertex);
423 
424  int clusterindex = 0;
425  for(auto c : inputcont.all()) {
426  clusterindex++;
427  if(!cuts.ClusterIsSelected(c, fInputEvent, fMCEvent, fIsMC, 1., c->GetID())) continue; // weight to be added later
428 
429  // TLorentzvector with cluster
430  TLorentzVector clusterVector;
431  c->GetMomentum(clusterVector,vertex);
432 
433  // convert to AODConversionPhoton
434  AliAODConversionPhoton photonCandidate(&clusterVector);
435 
436  // Flag Photon as CaloPhoton
437  photonCandidate.SetIsCaloPhoton();
438  photonCandidate.SetCaloClusterRef(clusterindex);
439 
440  // get MC label
441  if(fIsMC>0){
442  photonCandidate.SetNCaloPhotonMCLabels(c->GetNLabels());
443  for (UInt_t k = 0; k < c->GetNLabels(); k++){
444  if(k < 50) photonCandidate.SetCaloPhotonMCLabel(k,c->GetLabels()[k]);
445  }
446  }
447 
448  candidates.push_back(photonCandidate);
449  }
450 
451  return candidates;
452 }
453 
454 //=================================== MAKE CONVERSION PHOTON CANDIDATES ====================================================================
456  std::vector<AliAODConversionPhoton> candidates;
457  Int_t nV0 = 0;
458  std::vector<AliAODConversionPhoton *> GammaCandidatesStepOne;
459  TList GammaCandidatesStepTwo;
460 
461  // Loop over Photon Candidates allocated by ReaderV1
462  for(auto photon : reader){
463  if(!cuts.PhotonIsSelected(photon ,fInputEvent)) continue;
464  if(!cuts.InPlaneOutOfPlaneCut(photon->GetPhotonPhi(), fEventPlaneAngle)) continue;
465  if(!cuts.UseElecSharingCut() && !cuts.UseToCloseV0sCut()){
466  candidates.push_back(*(static_cast<AliAODConversionPhoton *>(photon))); // if no second loop is required add to events good gammas
467  }else if(cuts.UseElecSharingCut()){ // if Shared Electron cut is enabled, Fill array, add to step one
468  cuts.FillElectonLabelArray(static_cast<AliAODConversionPhoton *>(photon), nV0);
469  nV0++;
470  GammaCandidatesStepOne.push_back(static_cast<AliAODConversionPhoton *>(photon));
471  }else if(!cuts.UseElecSharingCut() && cuts.UseToCloseV0sCut()){ // shared electron is disabled, step one not needed -> step two
472  GammaCandidatesStepTwo.Add(static_cast<AliAODConversionPhoton *>(photon));
473  }
474  }
475 
476  if(cuts.UseElecSharingCut()){
477  int iV0 = 0;
478  for(auto photon : GammaCandidatesStepOne){
479  if(!cuts.RejectSharedElectronV0s(photon,iV0,GammaCandidatesStepOne.size())) continue;
480  if(!cuts.UseToCloseV0sCut()){ // To Close v0s cut diabled, step two not needed
481  candidates.push_back(*photon);
482  } else GammaCandidatesStepTwo.Add(photon); // Close v0s cut enabled -> add to list two
483  iV0++;
484  }
485  }
486 
487  if(cuts.UseToCloseV0sCut()){
488  for(int i = 0; i < GammaCandidatesStepTwo.GetEntries(); i++){
489  AliAODConversionPhoton *photon = static_cast<AliAODConversionPhoton *>(GammaCandidatesStepTwo.At(i));
490  if(!cuts.RejectToCloseV0s(photon, &GammaCandidatesStepTwo,i)) continue;
491  candidates.push_back(*photon); // Add gamma to current cut TList
492  }
493  }
494  return candidates;
495 }
496 
497 //=================================== SELECT MESON ====================================================================
498 std::vector<AliAODConversionMother> AliAnalysisTaskK0toPi0Pi0::SelectMeson(std::vector<AliAODConversionMother> &candidates,
499  AliConversionMesonCuts &cuts, MesonType_t meson, const char *reccase){
500  std::vector<AliAODConversionMother> selectedCandidates;
501  TString mesonName;
502  switch(meson) {
503  case kPi0: mesonName = "Pi0"; break;
504  case kK0: mesonName = "K0"; break;
505  };
506  TString qaname = "h" + mesonName + "Selection" + reccase;
507  for(auto candidate: candidates){
508  Int_t selectionStatus = cuts.MesonIsSelected(&candidate, kTRUE, 0);
509  fHistos->FillTH1(qaname, selectionStatus);
510  if(!selectionStatus) continue;
511  selectedCandidates.push_back(candidate);
512  }
513 
514  return selectedCandidates;
515 
516 
517 }
518 
519 //=================================== MAKE PI0 CANDIDATES ====================================================================
520 std::vector<AliAODConversionMother> AliAnalysisTaskK0toPi0Pi0::MakePi0Candidates(const std::vector<AliAODConversionPhoton> *primaryLeg,
521  const std::vector<AliAODConversionPhoton> *secondaryLeg,
522  AliConversionMesonCuts &cuts){
523  // secondary leg: optional argument, if different methods for photon identification (i.e. PCM-EMCAL) is used
524  AliDebug(1, Form("Make Pi0 candidates: Number of photons in first leg: %lu, second leg: %lu", primaryLeg->size(), secondaryLeg ? secondaryLeg->size() : 0));
525  std::vector<AliAODConversionMother> candidates;
526  if(secondaryLeg){
527  // Different methods for photon identification identification
528  for(auto primphoton : *primaryLeg){
529  for(auto secphoton : *secondaryLeg) {
530  AliAODConversionMother candidate(&primphoton, &secphoton);
531  AliDebug(2, Form("Made Pi0 candidate same - Mass %f [%f - %f] GeV/c2", candidate.M(), cuts.GetSelectionLow(), cuts.GetSelectionHigh()));
532  //if(!cuts.CheckWhetherInMassRange(candidate.M()))continue;
533  if(candidate.M() < 1e-4 || candidate.M() > 0.2)continue;
534  AliDebug(2, "Candidate in mass window");
535  candidates.push_back(candidate);
536  }
537  }
538  } else {
539  // Same method for photon identification
540  for(auto primiter = primaryLeg->begin(); primiter != primaryLeg->end(); ++primiter){
541  for(auto seciter = primiter + 1; seciter != primaryLeg->end(); ++seciter){
542  AliAODConversionMother candidate(&(*primiter), &(*seciter));
543  AliDebug(2, Form("Made Pi0 candidate mixed - Mass %f [%f - %f] GeV/c2", candidate.M(), cuts.GetSelectionLow(), cuts.GetSelectionHigh()));
544  //if(!cuts.CheckWhetherInMassRange(candidate.M()))continue;
545  if(candidate.M() < 1e-4 || candidate.M() > 0.2)continue;
546  AliDebug(2, "Candidate in mass window");
547  candidates.push_back(candidate);
548  }
549  }
550  }
551  AliDebug(1, Form("Found %lu pi0 candidates in event\n", candidates.size()));
552  return candidates;
553 }
554 
555 // =================================== MAKE K0 SHORT CANDIDATES ====================================================================
556 std::vector<AliAODConversionMother> AliAnalysisTaskK0toPi0Pi0::MakeK0ShortCandidates(const std::vector<AliAODConversionMother> *primaryLeg,
557  const std::vector<AliAODConversionMother> *secondaryLeg,
558  AliConversionMesonCuts &cuts){
559  std::vector<AliAODConversionMother> candidates;
560  if(secondaryLeg) {
561  // Different methods for Pi0 identification (one same, one mixed)
562  for(const auto &primpi0 : *primaryLeg) {
563  for(const auto &secpi0 : *secondaryLeg) {
564  AliAODConversionMother candidate(&primpi0, &secpi0);
565  candidates.push_back(candidate);
566  }
567  }
568  } else {
569  // Same methods for Pi0 identification (both same or both mixed)
570  for(auto primpi0 = primaryLeg->begin(); primpi0 != primaryLeg->end(); ++primpi0) {
571  for(auto secpi0 = primpi0 + 1; secpi0 != primaryLeg->end(); ++secpi0) {
572  AliAODConversionMother candidate(&(*primpi0), &(*secpi0));
573  candidates.push_back(candidate);
574  }
575  }
576  }
577  return candidates;
578 }
579 
580 
581 // =================================== MAKE K0 SHORT CANDIDATES MIXED ====================================================================
582 std::vector<AliAODConversionMother> AliAnalysisTaskK0toPi0Pi0::MakeK0ShortCandidatesMixed(const std::vector<AliAODConversionMother> *sameEvent,
583  const std::vector<AliAODConversionMother *> *mixedEvent,
584  AliConversionMesonCuts &cuts){
585  std::vector<AliAODConversionMother> candidates;
586  // Different methods for Pi0 identification (one same, one mixed)
587  for(const auto &primpi0 : *sameEvent) {
588  for(const auto secpi0 : *mixedEvent) {
589  AliAODConversionMother candidate(&primpi0, secpi0);
590  candidates.push_back(candidate);
591  }
592  }
593  return candidates;
594 }
595 //=================================== MAKE PHOTON QA CALO ====================================================================
596 void AliAnalysisTaskK0toPi0Pi0::MakePhotonQACalo(const std::vector<AliAODConversionPhoton> &photons, AliConvEventCuts &cuts) {
597  for(const auto &photon : photons) {
598  fHistos->FillTH1("hCaloPhotonPt", photon.Pt());
599  }
600 }
601 
602 //=================================== MAKE PHOTON QA CONV ====================================================================
603 void AliAnalysisTaskK0toPi0Pi0::MakePhotonQAConv(const std::vector<AliAODConversionPhoton> &photons, AliConvEventCuts &cuts) {
604  for(const auto &photon : photons) {
605  fHistos->FillTH1("hConvPhotonPt", photon.Pt());
606  fHistos->FillTH2("hConvPhotonEtaR", photon.Eta(), photon.GetConversionRadius());
607  }
608 }
609 
610 //=================================== MAKE PI0 QA ====================================================================
611 void AliAnalysisTaskK0toPi0Pi0::MakePi0QA(const std::vector<AliAODConversionMother> &pi0s, const char *reccase, TString selectionStatus){
612  TString reccaseString = reccase;
613  fHistos->FillTH1("hNPi0CandidatesPerEvent" + selectionStatus + reccaseString, pi0s.size());
614  for(const auto &pi0 : pi0s) {
615  fHistos->FillTH2("hMassvsPtPi0" + selectionStatus + reccaseString + "All", pi0.M(), pi0.Pt());
616  // if in the pi0 mass region
617  if((1e-4 <=pi0.M()) && (pi0.M()<= 0.2)){
618  fHistos->FillTH2("hMassvsPtPi0" + selectionStatus + reccaseString + "Sel", pi0.M(),pi0.Pt());
619  fHistos->FillTH2("hAlphavsPtPi0" + selectionStatus + reccaseString, pi0.GetAlpha(), pi0.Pt());
620  fHistos->FillTH2("hOpeningAnglevsPtPi0" + selectionStatus + reccaseString, pi0.GetOpeningAngle(), pi0.Pt());
621  }
622  }
623 }
624 
625 //=================================== MAKE KO SHORT QA ====================================================================
626 void AliAnalysisTaskK0toPi0Pi0::MakeK0ShortQA(const std::vector<AliAODConversionMother> &k0s,const char *reccase, TString selectionStatus){
627  TString reccaseString = reccase;
628  if (selectionStatus != "BKG"){
629  fHistos->FillTH1("hNK0CandidatesPerEvent" + selectionStatus + reccaseString, k0s.size());
630  }
631 
632  for(const auto &k0: k0s) {
633  fHistos->FillTH2("hMassvsPtK0Short" + selectionStatus + reccaseString, k0.M(), k0.Pt());
634  fHistos->FillTH2("hOpeningAnglevsPtK0Short" + selectionStatus + reccaseString, k0.GetOpeningAngle(), k0.Pt());
635  }
636 }
637 
638 //=================================== ADD CLUSTER CONTAINER ====================================================================
641  return fClusterContainer;
642 }
643 
644 
645 
Bool_t fIsMC
Switch whether we run over data or MC.
AliClusterContainer * AddClusterContainer(const char *name)
void MakePi0QA(const std::vector< AliAODConversionMother > &pi0s, const char *reccase, TString selectionStatus)
void SetCaloClusterRef(Long_t ref)
double Double_t
Definition: External.C:58
Bool_t RejectSharedElectronV0s(AliAODConversionPhoton *photon, Int_t nV0, Int_t nV0s)
AliGammaConversionAODBGHandler * fSameEMCALHandler
! Background Handler for same EMC
Int_t GetNReconstructedGammas() const
Definition: AliV0ReaderV1.h:86
Class creating a linear binning, used in the histogram manager.
TList * GetCutHistograms()
AliCaloPhotonCuts * fCaloPhotonCuts
Calo photon cuts.
Int_t GetNumberOfPrimaryTracks()
Bool_t ClusterIsSelected(AliVCluster *cluster, AliVEvent *event, AliMCEvent *mcEvent, Int_t isMC, Double_t weight=1., Long_t clusterID=-1)
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
TList * GetEventCutHistograms()
Definition: AliV0ReaderV1.h:93
void AddMesonEvent(TList *const eventMothers, Double_t xvalue, Double_t yvalue, Double_t zvalue, Int_t multiplicity, Double_t epvalue=-100)
TCanvas * c
Definition: TestFitELoss.C:172
TList * GetCutHistograms()
Definition: AliV0ReaderV1.h:91
AliGammaConversionAODBGHandler * fMixedHandler
! Background Handler for mixed case
AliClusterContainer * fClusterContainer
Cluster container.
void SetCaloPhotonMCLabel(Int_t i, Int_t labelCaloPhoton)
Double_t fEventPlaneAngle
Event Plane Angle.
void FillElectonLabelArray(AliAODConversionPhoton *photon, Int_t nV0)
std::vector< AliAODConversionPhoton > MakeConversionPhotonCandidates(const AliV0ReaderV1 &reader, AliConversionPhotonCuts &cuts)
TList * fOutput
Global output container.
AliConversionMesonCuts * fPi0CutsCaloCalo
Cuts on the pi0 for the calo calo case.
AliConversionMesonCuts * fPi0CutsConvConv
Cuts on the pi0 for the conv conv case.
const AliClusterIterableContainer all() const
Bool_t RejectToCloseV0s(AliAODConversionPhoton *photon, TList *photons, Int_t nV0)
void MakePhotonQACalo(const std::vector< AliAODConversionPhoton > &photons, AliConvEventCuts &cuts)
Bool_t InPlaneOutOfPlaneCut(Double_t photonPhi, Double_t eventPlaneAngle=-100, Bool_t fill=kTRUE)
Int_t IsEventAcceptedByCut(AliConvEventCuts *ReaderCuts, AliVEvent *event, AliMCEvent *mcEvent, Int_t isHeavyIon, Bool_t isEMCALAnalysis)
int Int_t
Definition: External.C:63
Bool_t fLocalInitialized
Check whether the task was initialized (triggers ExecOnce)
Class handling all kinds of selection cuts for Gamma Calo analysis.
unsigned int UInt_t
Definition: External.C:33
void FillHistogramsExtendedQA(AliVEvent *event, Int_t isMC)
THistManager * fHistos
Container for Histograms.
AliConversionMesonCuts * fPi0CutsConvCalo
Cuts on the pi0 for the conv calo case.
Double_t GetSelectionLow() const
AliConversionPhotonCuts * fConvPhotonCuts
Cuts on conversion photons.
Class handling all kinds of selection cuts for Gamma Conversion analysis.
void MakeK0ShortQA(const std::vector< AliAODConversionMother > &k0s, const char *reccase, TString selectionStatus)
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
Fill a 1D histogram within the container.
std::vector< AliAODConversionMother > MakeK0ShortCandidates(const std::vector< AliAODConversionMother > *primaryLeg, const std::vector< AliAODConversionMother > *secondaryLeg, AliConversionMesonCuts &cuts)
Double_t GetSelectionHigh() const
Class handling analysis of K0s decay into two pi0s.
AliV0ReaderV1 * fV0Reader
! V0 reader
void MakePhotonQAConv(const std::vector< AliAODConversionPhoton > &photons, AliConvEventCuts &cuts)
AliGammaConversionMotherAODVector * GetBGGoodMesons(Int_t zbin, Int_t mbin, Int_t event)
TString fV0ReaderName
Name of the V0 reader.
Class handling all kinds of selection cuts for Gamma Conversion analysis.
Bool_t MesonIsSelected(AliAODConversionMother *pi0, Bool_t IsSignal=kTRUE, Double_t fRapidityShift=0., Int_t leadingCellID1=0, Int_t leadingCellID2=0)
std::vector< AliAODConversionMother > MakePi0Candidates(const std::vector< AliAODConversionPhoton > *primaryLeg, const std::vector< AliAODConversionPhoton > *secondaryLeg, AliConversionMesonCuts &cuts)
std::vector< AliAODConversionPhoton > MakeCaloPhotonCandidates(const AliClusterContainer &inputcont, AliCaloPhotonCuts &cuts)
void SetNCaloPhotonMCLabels(Int_t nLabels)
std::vector< AliAODConversionMother > MakeK0ShortCandidatesMixed(const std::vector< AliAODConversionMother > *sameEvent, const std::vector< AliAODConversionMother * > *mixedEvent, AliConversionMesonCuts &cuts)
Container class for histograms.
Definition: THistManager.h:99
Class handling all kinds of selection cuts for Gamma Conversion analysis.
std::vector< AliAODConversionMother > SelectMeson(std::vector< AliAODConversionMother > &candidates, AliConversionMesonCuts &cuts, MesonType_t meson, const char *reccase)
void SetArray(const AliVEvent *event)
AliConvEventCuts * GetEventCuts()
Definition: AliV0ReaderV1.h:90
const char Option_t
Definition: External.C:48
Int_t fCurrentRun
Current run number (triggers RunChanged)
AliGammaConversionAODBGHandler * fSamePCMHandler
! Background Handler for same PCM
Container structure for EMCAL clusters.
TString meson
AliConversionMesonCuts * fK0Cuts
Cuts on the K0.
Bool_t PhotonIsSelected(AliConversionPhotonBase *photon, AliVEvent *event)
AliConvEventCuts * fEventCuts
Event cuts.