]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/vertexingHF/AliAnalysisTaskSELc2V0bachelor.cxx
Updates in Lc->V0bachelor analysis (Annalisa)
[u/mrichter/AliRoot.git] / PWGHF / vertexingHF / AliAnalysisTaskSELc2V0bachelor.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2009, 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  * appeuear 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 /* $Id$ */
17
18 //
19 //
20 //               Base class for Lc2V0 Analysis
21 //
22 //
23 //  The Lc spectra study is done 2D histograms:
24 //   cascade_invariantMass VS cascade_pT
25 //
26 //  Cuts have been centralized in AliRDHFCutsLctoV0 class
27 //
28 //-------------------------------------------------------------------------
29 //
30 //                 Authors: A.De Caro(a,b), P. Pagano(b)
31 //  (a) Centro 'E.Fermi' - Roma
32 //  (b) INFN and University of Salerno
33 //
34 //  Contatcs: decaro@sa.infn.it
35 //            paola.pagano@sa.infn.it
36 //-------------------------------------------------------------------------
37
38 #include <TSystem.h>
39 #include <TParticle.h>
40 #include <TParticlePDG.h>
41 #include <TH1F.h>
42 #include <TH1I.h>
43 #include <TH2F.h>
44 #include <TTree.h>
45 #include "TROOT.h"
46 #include <TDatabasePDG.h>
47 #include <AliAnalysisDataSlot.h>
48 #include <AliAnalysisDataContainer.h>
49 #include "AliStack.h"
50 #include "AliMCEvent.h"
51 #include "AliAnalysisManager.h"
52 #include "AliAODMCHeader.h"
53 #include "AliAODHandler.h"
54 #include "AliLog.h"
55 #include "AliAODVertex.h"
56 #include "AliAODRecoDecay.h"
57 #include "AliAODRecoDecayHF.h"
58 #include "AliAODRecoCascadeHF.h"
59 #include "AliAnalysisVertexingHF.h"
60 #include "AliESDtrack.h"
61 #include "AliAODTrack.h"
62 #include "AliAODv0.h"
63 #include "AliAODMCParticle.h"
64 #include "AliAnalysisTaskSE.h"
65 #include "AliAnalysisTaskSELc2V0bachelor.h"
66 #include "AliNormalizationCounter.h"
67 #include "AliAODPidHF.h"
68 #include "AliPIDResponse.h"
69 #include "AliTOFPIDResponse.h"
70 #include "AliInputEventHandler.h"
71
72 using std::cout;
73 using std::endl;
74
75 ClassImp(AliAnalysisTaskSELc2V0bachelor)
76
77 //__________________________________________________________________________
78 AliAnalysisTaskSELc2V0bachelor::AliAnalysisTaskSELc2V0bachelor():  
79   AliAnalysisTaskSE(),
80   fUseMCInfo(kFALSE),
81   fOutput(0),
82   fOutputAll(0),
83   fOutputPIDBach(0),
84   fCEvents(0),
85   fPIDResponse(0),
86   fIsK0sAnalysis(kFALSE),
87   fCounter(0),
88   fProdCuts(0),
89   fAnalCuts(0),
90   fListCuts(0),
91   fUseOnTheFlyV0(kFALSE),
92   fIsEventSelected(kFALSE),
93   fWriteVariableTree(kFALSE),
94   fVariablesTree(0),
95   fCandidateVariables(),
96   fVtx1(0),
97   fBzkG(0)
98 {
99   //
100   // Default ctor
101   //
102 }
103 //___________________________________________________________________________
104 AliAnalysisTaskSELc2V0bachelor::AliAnalysisTaskSELc2V0bachelor(const Char_t* name, AliRDHFCutsLctoV0* prodCuts,
105                                                                AliRDHFCutsLctoV0* analCuts, Bool_t useOnTheFly,
106                                                                Bool_t writeVariableTree) :
107   AliAnalysisTaskSE(name),
108   fUseMCInfo(kFALSE),
109   fOutput(0),
110   fOutputAll(0),
111   fOutputPIDBach(0),
112   fCEvents(0),
113   fPIDResponse(0),
114   fIsK0sAnalysis(kFALSE),
115   fCounter(0),
116   fProdCuts(prodCuts),
117   fAnalCuts(analCuts),
118   fListCuts(0),
119   fUseOnTheFlyV0(useOnTheFly),
120   fIsEventSelected(kFALSE),
121   fWriteVariableTree(writeVariableTree),
122   fVariablesTree(0),
123   fCandidateVariables(),
124   fVtx1(0),
125   fBzkG(0)
126 {
127   //
128   // Constructor. Initialization of Inputs and Outputs
129   //
130   Info("AliAnalysisTaskSELc2V0bachelor","Calling Constructor");
131
132   DefineOutput(1,TList::Class());  //conters
133   DefineOutput(2,TList::Class());  //All Entries output
134   DefineOutput(3,TList::Class());  //3sigma PID output
135   DefineOutput(4,AliNormalizationCounter::Class());
136   DefineOutput(5,TList::Class());
137
138   // Output slot #6 keeps a tree of the candidate variables after track selection
139   if (fWriteVariableTree) DefineOutput(6,TTree::Class());  //My private output
140
141 }
142
143 //___________________________________________________________________________
144 AliAnalysisTaskSELc2V0bachelor::~AliAnalysisTaskSELc2V0bachelor() {
145   //
146   // destructor
147   //
148   Info("~AliAnalysisTaskSELc2V0bachelor","Calling Destructor");
149   
150   if (fOutput) {
151     delete fOutput;
152     fOutput = 0;
153   }
154
155   if (fOutputAll) {
156     delete fOutputAll;
157     fOutputAll = 0;
158   }
159
160   if (fOutputPIDBach) {
161     delete fOutputPIDBach;
162     fOutputPIDBach = 0;
163   }
164
165   if (fPIDResponse) {
166     delete  fPIDResponse;
167   }
168
169   if (fCounter) {
170     delete fCounter;
171     fCounter = 0;
172   }
173
174   if (fProdCuts) {
175     delete fProdCuts;
176     fProdCuts = 0;
177   }
178
179   if (fAnalCuts) {
180     delete fAnalCuts;
181     fAnalCuts = 0;
182   }
183
184   if (fListCuts) {
185     delete fListCuts;
186     fListCuts = 0;
187   }
188
189   if(fVariablesTree){
190     delete fVariablesTree;
191     fVariablesTree = 0;
192   }
193
194 }
195 //_________________________________________________
196 void AliAnalysisTaskSELc2V0bachelor::Init() {
197   //
198   // Initialization
199   //
200
201   fIsEventSelected=kFALSE;
202
203   if (fDebug > 1) AliInfo("Init");
204
205   fListCuts = new TList();
206   fListCuts->SetOwner();
207   fListCuts->Add(new AliRDHFCutsLctoV0(*fProdCuts));
208   fListCuts->Add(new AliRDHFCutsLctoV0(*fAnalCuts));
209   PostData(5,fListCuts);
210
211   return;
212 }
213
214 //_________________________________________________
215 void AliAnalysisTaskSELc2V0bachelor::UserExec(Option_t *)
216 {
217   // user exec
218   if (!fInputEvent) {
219     AliError("NO EVENT FOUND!");
220     return;
221   }
222
223   AliAODEvent* aodEvent = dynamic_cast<AliAODEvent*>(fInputEvent);
224   TClonesArray *arrayLctopKos=0;
225
226   if (!aodEvent && AODEvent() && IsStandardAOD()) {
227     // In case there is an AOD handler writing a standard AOD, use the AOD 
228     // event in memory rather than the input (ESD) event.    
229     aodEvent = dynamic_cast<AliAODEvent*> (AODEvent());
230     // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
231     // have to taken from the AOD event hold by the AliAODExtension
232     AliAODHandler* aodHandler = (AliAODHandler*) 
233       ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
234    
235     if (aodHandler->GetExtensions()) {
236       AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
237       AliAODEvent *aodFromExt = ext->GetAOD();
238       arrayLctopKos=(TClonesArray*)aodFromExt->GetList()->FindObject("CascadesHF");
239     }
240   } else {
241     arrayLctopKos=(TClonesArray*)aodEvent->GetList()->FindObject("CascadesHF");
242   }
243
244   fCEvents->Fill(1);
245   fCounter->StoreEvent(aodEvent,fAnalCuts,fUseMCInfo);
246
247   // AOD primary vertex
248   fVtx1 = (AliAODVertex*)aodEvent->GetPrimaryVertex();
249   if (!fVtx1) return;
250
251   // fix for temporary bug in ESDfilter 
252   fBzkG = (Double_t)aodEvent->GetMagneticField(); 
253   if (TMath::Abs(fBzkG)<0.001) return;
254   fCEvents->Fill(2);
255
256   Float_t zVertex = fVtx1->GetZ();
257   ((TH1F*)(fOutput->FindObject("hZ2")))->Fill(zVertex);
258
259   if (fVtx1->GetNContributors()<1) return;
260   fCEvents->Fill(3);
261
262   ((TH1F*)(fOutput->FindObject("hZ3")))->Fill(zVertex);
263
264   if (!arrayLctopKos) {
265     AliInfo("Could not find array of HF cascades, skipping the event");
266     return;
267   } else {
268     if (arrayLctopKos->GetEntriesFast()) {
269       AliInfo(Form("Found %d cascades",arrayLctopKos->GetEntriesFast()));
270     }
271   }
272   fCEvents->Fill(4);
273   ((TH1F*)(fOutput->FindObject("hZ4")))->Fill(zVertex);
274
275   ///////////////////////
276   Bool_t check1 = kFALSE;
277   TString firedTriggerClasses = aodEvent->GetFiredTriggerClasses(); // trigger class
278   if ( !fUseMCInfo && // don't do for MC...
279        (aodEvent->GetRunNumber()<136851 || aodEvent->GetRunNumber()>139517) ) { // ...and for PbPb 2010 data
280     if ( !(firedTriggerClasses.Contains("CINT1")) ) {
281       AliInfo(Form(" ======================== firedTriggerClasses.Data() = %s",firedTriggerClasses.Data()));
282       fCEvents->Fill(8);
283       ((TH1F*)(fOutput->FindObject("hZ8")))->Fill(zVertex);
284       check1 = kTRUE;
285     }
286   }
287
288   ULong64_t fTriggerMask=AliVEvent::kAnyINT;
289   Bool_t isSelectedAAA = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & fTriggerMask);
290   if (!isSelectedAAA) {
291     fCEvents->Fill(9);
292     ((TH1F*)(fOutput->FindObject("hZ9")))->Fill(zVertex);
293   }
294
295   if (!isSelectedAAA || check1) {
296     fCEvents->Fill(16);
297     ((TH1F*)(fOutput->FindObject("hZ16")))->Fill(zVertex);
298   }
299
300   fTriggerMask=AliVEvent::kAny;
301   Bool_t isSelectedBBB = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & fTriggerMask);
302   if (!isSelectedBBB) {
303     fCEvents->Fill(10);
304     ((TH1F*)(fOutput->FindObject("hZ10")))->Fill(zVertex);
305   }
306
307   TString titleVtx=fVtx1->GetTitle();
308   if (titleVtx.Contains("Z")) {
309     fCEvents->Fill(11);
310     ((TH1F*)(fOutput->FindObject("hZ11")))->Fill(zVertex);
311   }
312   else if (titleVtx.Contains("3D")) {
313     fCEvents->Fill(12);
314     ((TH1F*)(fOutput->FindObject("hZ12")))->Fill(zVertex);
315   } else {
316     fCEvents->Fill(13);
317     ((TH1F*)(fOutput->FindObject("hZ13")))->Fill(zVertex);
318   }
319
320   if (TMath::Abs(zVertex)<=fAnalCuts->GetMaxVtxZ()) {
321     fCEvents->Fill(14);
322     ((TH1F*)(fOutput->FindObject("hZ14")))->Fill(zVertex);
323   }
324
325   fIsEventSelected = fAnalCuts->IsEventSelected(aodEvent);
326   if ( fIsEventSelected ) {
327     fCEvents->Fill(7);
328     ((TH1F*)(fOutput->FindObject("hZ7")))->Fill(zVertex);
329   } else {
330     fCEvents->Fill(15);
331     ((TH1F*)(fOutput->FindObject("hZ15")))->Fill(zVertex);
332   }
333   ///////////////////////
334
335   if ( !fIsEventSelected ) return; // don't take into account not selected events 
336
337   // mc analysis 
338   TClonesArray *mcArray = 0;
339   AliAODMCHeader *mcHeader=0;
340
341   if (fUseMCInfo) {
342     // MC array need for maching
343     mcArray = dynamic_cast<TClonesArray*>(aodEvent->FindListObject(AliAODMCParticle::StdBranchName()));
344     if (!mcArray) {
345       AliError("Could not find Monte-Carlo in AOD");
346       return;
347     }
348     fCEvents->Fill(5); // in case of MC events
349     ((TH1F*)(fOutput->FindObject("hZ5")))->Fill(zVertex);
350
351     // load MC header
352     mcHeader = (AliAODMCHeader*)aodEvent->GetList()->FindObject(AliAODMCHeader::StdBranchName());
353     if (!mcHeader) {
354       AliError("AliAnalysisTaskSELc2V0bachelor::UserExec: MC header branch not found!\n");
355       return;
356     }
357     fCEvents->Fill(6);
358     ((TH1F*)(fOutput->FindObject("hZ6")))->Fill(zVertex);
359
360     // check on MC Lc Daughter
361     for (Int_t iii=0; iii<mcArray->GetEntries(); iii++) {
362       SearchLcDaughter(mcArray,iii);
363     }
364
365   }
366
367   Int_t nSelectedProd = 0;
368   Int_t nSelectedAnal = 0;
369   if (fIsK0sAnalysis) {
370     MakeAnalysisForLc2prK0S(arrayLctopKos,mcArray,
371                             nSelectedProd, fProdCuts, nSelectedAnal, fAnalCuts);
372
373     if (nSelectedAnal) {
374
375       ((TH1I*)(fOutput->FindObject("hEventsWithCandidates")))->Fill(4);
376       ((TH1F*)(fOutput->FindObject("hZ4a")))->Fill(zVertex);
377
378       Bool_t check1a = kFALSE;
379       if ( !fUseMCInfo && // don't do for MC...
380            (aodEvent->GetRunNumber()<136851 || aodEvent->GetRunNumber()>139517) ) { // ...and for PbPb 2010 data
381         if ( !(firedTriggerClasses.Contains("CINT1")) ) {
382           AliInfo(Form(" ======================== firedTriggerClasses.Data() = %s",firedTriggerClasses.Data()));
383           ((TH1I*)(fOutput->FindObject("hEventsWithCandidates")))->Fill(8);
384           ((TH1F*)(fOutput->FindObject("hZ8a")))->Fill(zVertex);
385           check1a = kTRUE;
386         }
387       }
388
389       fTriggerMask=AliVEvent::kAnyINT;
390       Bool_t isSelectedAAAa = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & fTriggerMask);
391       if (!isSelectedAAAa) {
392         ((TH1I*)(fOutput->FindObject("hEventsWithCandidates")))->Fill(9);
393         ((TH1F*)(fOutput->FindObject("hZ9a")))->Fill(zVertex);
394       }
395
396       if (!isSelectedAAAa || check1a) {
397         ((TH1I*)(fOutput->FindObject("hEventsWithCandidates")))->Fill(16);
398         ((TH1F*)(fOutput->FindObject("hZ16a")))->Fill(zVertex);
399       }
400
401       fTriggerMask=AliVEvent::kAny;
402       Bool_t isSelectedBBBa = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & fTriggerMask);
403       if (!isSelectedBBBa) {
404         ((TH1I*)(fOutput->FindObject("hEventsWithCandidates")))->Fill(10);
405         ((TH1F*)(fOutput->FindObject("hZ10a")))->Fill(zVertex);
406       }
407
408       if (titleVtx.Contains("Z")) {
409         ((TH1I*)(fOutput->FindObject("hEventsWithCandidates")))->Fill(11);
410         ((TH1F*)(fOutput->FindObject("hZ11a")))->Fill(zVertex);
411       }
412       else if (titleVtx.Contains("3D")) {
413         ((TH1I*)(fOutput->FindObject("hEventsWithCandidates")))->Fill(12);
414         ((TH1F*)(fOutput->FindObject("hZ12a")))->Fill(zVertex);
415       } else {
416         ((TH1I*)(fOutput->FindObject("hEventsWithCandidates")))->Fill(13);
417         ((TH1F*)(fOutput->FindObject("hZ13a")))->Fill(zVertex);
418       }
419
420       if (TMath::Abs(zVertex)<=fAnalCuts->GetMaxVtxZ()) {
421         ((TH1I*)(fOutput->FindObject("hEventsWithCandidates")))->Fill(14);
422         ((TH1F*)(fOutput->FindObject("hZ14a")))->Fill(zVertex);
423       }
424
425       if ( fIsEventSelected ) {
426         ((TH1I*)(fOutput->FindObject("hEventsWithCandidates")))->Fill(7);
427         ((TH1F*)(fOutput->FindObject("hZ7a")))->Fill(zVertex);
428       } else {
429         ((TH1I*)(fOutput->FindObject("hEventsWithCandidates")))->Fill(15);
430         ((TH1F*)(fOutput->FindObject("hZ15a")))->Fill(zVertex);
431       }
432     }
433
434   }
435
436
437   fCounter->StoreCandidates(aodEvent,nSelectedProd,kTRUE);
438   fCounter->StoreCandidates(aodEvent,nSelectedAnal,kFALSE);
439
440   PostData(1,fOutput);
441   PostData(2,fOutputAll);
442   PostData(3,fOutputPIDBach);
443   PostData(4,fCounter);
444   if (fWriteVariableTree) PostData(6,fVariablesTree);
445
446 }
447 //________________________________________ terminate ___________________________
448 void AliAnalysisTaskSELc2V0bachelor::Terminate(Option_t*)
449 {    
450   // The Terminate() function is the last function to be called during
451   // a query. It always runs on the client, it can be used to present
452   // the results graphically or save the results to file.
453   
454   //AliInfo("Terminate","");
455   AliAnalysisTaskSE::Terminate();
456   
457   fOutput = dynamic_cast<TList*> (GetOutputData(1));
458   if (!fOutput) {     
459     AliError("fOutput not available");
460     return;
461   }
462   
463   //fCEvents = dynamic_cast<TH1F*>(fOutput->FindObject("fCEvents"));
464
465   fOutputAll = dynamic_cast<TList*> (GetOutputData(2));
466   if (!fOutputAll) {
467     AliError("fOutputAll not available");
468     return;
469   }
470
471   fOutputPIDBach = dynamic_cast<TList*> (GetOutputData(3));
472   if (!fOutputPIDBach) {
473     AliError("fOutputPIDBach not available");
474     return;
475   }
476
477   return;
478 }
479 //___________________________________________________________________________
480 void AliAnalysisTaskSELc2V0bachelor::UserCreateOutputObjects() { 
481   // output
482   AliInfo(Form("CreateOutputObjects of task %s\n", GetName()));
483   
484   //slot #1  
485   //OpenFile(1);
486   fOutput = new TList();
487   fOutput->SetOwner();
488   fOutput->SetName("chist0");
489
490   fOutputAll = new TList();
491   fOutputAll->SetOwner();
492   fOutputAll->SetName("listAll");
493
494   fOutputPIDBach = new TList();
495   fOutputPIDBach->SetOwner();
496   fOutputPIDBach->SetName("listPIDBach");
497
498   // define histograms
499   DefineHistograms();
500   
501   AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
502   AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
503   fPIDResponse = inputHandler->GetPIDResponse();
504
505   if (fProdCuts->GetIsUsePID()){
506     fProdCuts->GetPidHF()->SetPidResponse(fPIDResponse);
507     fProdCuts->GetPidV0pos()->SetPidResponse(fPIDResponse);
508     fProdCuts->GetPidV0neg()->SetPidResponse(fPIDResponse);
509     fProdCuts->GetPidHF()->SetOldPid(kFALSE);
510     fProdCuts->GetPidV0pos()->SetOldPid(kFALSE);
511     fProdCuts->GetPidV0neg()->SetOldPid(kFALSE);
512   }
513   if (fAnalCuts->GetIsUsePID()){
514     fAnalCuts->GetPidHF()->SetPidResponse(fPIDResponse);
515     fAnalCuts->GetPidV0pos()->SetPidResponse(fPIDResponse);
516     fAnalCuts->GetPidV0neg()->SetPidResponse(fPIDResponse);
517     fAnalCuts->GetPidHF()->SetOldPid(kFALSE);
518     fAnalCuts->GetPidV0pos()->SetOldPid(kFALSE);
519     fAnalCuts->GetPidV0neg()->SetOldPid(kFALSE);
520   }
521
522   PostData(1,fOutput);
523   PostData(2,fOutputAll);
524   PostData(3,fOutputPIDBach);
525
526   fCounter = new AliNormalizationCounter("NormalizationCounter");
527   fCounter->Init();
528   PostData(4,fCounter);
529
530   // Output slot 6: tree of the candidate variables
531   if (fWriteVariableTree) {
532     const char* nameoutput = GetOutputSlot(6)->GetContainer()->GetName();
533     fVariablesTree = new TTree(nameoutput,"Candidates variables tree");
534     Int_t nVar = 80;
535     fCandidateVariables = new Float_t [nVar];
536     TString * fCandidateVariableNames = new TString[nVar];
537     fCandidateVariableNames[0]="isLcByMC";
538     fCandidateVariableNames[1]="isV0ByMC";
539     fCandidateVariableNames[2]="massLc2K0Sp";
540     fCandidateVariableNames[3]="massLc2Lambdapi";
541     fCandidateVariableNames[4]="massK0S";
542     fCandidateVariableNames[5]="massLambda";
543     fCandidateVariableNames[6]="massLambdaBar";
544     fCandidateVariableNames[7]="cosPAK0S";
545     fCandidateVariableNames[8]="dcaV0ptp";
546     fCandidateVariableNames[9]="tImpParBach";
547     fCandidateVariableNames[10]="tImpParV0";
548     fCandidateVariableNames[11]="nSigmaTPCpr";
549     fCandidateVariableNames[12]="nSigmaTPCpi";
550     fCandidateVariableNames[13]="nSigmaTPCka";
551     fCandidateVariableNames[14]="nSigmaTOFpr";
552     fCandidateVariableNames[15]="nSigmaTOFpi";
553     fCandidateVariableNames[16]="nSigmaTOFka";
554     fCandidateVariableNames[17]="bachelorPx";
555     fCandidateVariableNames[18]="bachelorPy";
556     fCandidateVariableNames[19]="bachelorPz";
557     fCandidateVariableNames[20]="V0positivePx";
558     fCandidateVariableNames[21]="V0positivePy";
559     fCandidateVariableNames[22]="V0positivePz";
560     fCandidateVariableNames[23]="V0negativePx";
561     fCandidateVariableNames[24]="V0negativePy";
562     fCandidateVariableNames[25]="V0negativePz";
563     fCandidateVariableNames[26]="qtLc";
564     fCandidateVariableNames[27]="alphaLc";
565     fCandidateVariableNames[28]="dcaV0postoPV";
566     fCandidateVariableNames[29]="dcaV0negtoPV";
567     fCandidateVariableNames[30]="bachelorPxDCA";
568     fCandidateVariableNames[31]="bachelorPyDCA";
569     fCandidateVariableNames[32]="bachelorPzDCA";
570     fCandidateVariableNames[33]="v0PxDCA";
571     fCandidateVariableNames[34]="v0PyDCA";
572     fCandidateVariableNames[35]="v0PzDCA";
573     fCandidateVariableNames[36]="V0positivePxDCA";
574     fCandidateVariableNames[37]="V0positivePyDCA";
575     fCandidateVariableNames[38]="V0positivePzDCA";
576     fCandidateVariableNames[39]="V0negativePxDCA";
577     fCandidateVariableNames[40]="V0negativePyDCA";
578     fCandidateVariableNames[41]="V0negativePzDCA";
579     fCandidateVariableNames[42]="flagToCheckCandidate";
580     fCandidateVariableNames[43]="massGamma";
581
582     fCandidateVariableNames[44]="bachelorP"; // @ prim vtx
583     fCandidateVariableNames[45]="bachelorPt"; // @ prim vtx
584     fCandidateVariableNames[46]="V0positiveP"; // @ prim vtx
585     fCandidateVariableNames[47]="V0positivePt"; // @ prim vtx
586     fCandidateVariableNames[48]="V0negativeP"; // @ prim vtx
587     fCandidateVariableNames[49]="V0negativePt"; // @ prim vtx
588     fCandidateVariableNames[50]="bachelorPDCA"; // @ DCA
589     fCandidateVariableNames[51]="bachelorPtDCA"; // @ DCA
590     fCandidateVariableNames[52]="v0PDCA"; // @ DCA
591     fCandidateVariableNames[53]="v0PtDCA"; // @ DCA
592     fCandidateVariableNames[54]="V0positivePDCA"; // @ DCA
593     fCandidateVariableNames[55]="V0positivePtDCA"; // @ DCA
594     fCandidateVariableNames[56]="V0negativePDCA"; // @ DCA
595     fCandidateVariableNames[57]="V0negativePtDCA"; // @ DCA
596     fCandidateVariableNames[58]="LcP"; // @ DCA
597     fCandidateVariableNames[59]="LcPt"; // @ DCA
598     fCandidateVariableNames[60]="v0P"; // @ V0 DCA
599     fCandidateVariableNames[61]="v0Pt"; // @ V0 DCA
600
601     fCandidateVariableNames[62]="cosPALc";
602     fCandidateVariableNames[63]="decayLengthLc";
603     fCandidateVariableNames[64]="decayLengthV0";
604
605     fCandidateVariableNames[65]="yLc";
606
607     fCandidateVariableNames[66]="massD2K0Spi"; // D+ -> pi+ K0S
608     fCandidateVariableNames[67]="massDS2K0SK"; // D+S -> K+ K0S
609
610     fCandidateVariableNames[68]="nSigmaITSpi"; // nSigmaITSpi
611     fCandidateVariableNames[69]="nSigmaITSka"; // nSigmaITSka
612     fCandidateVariableNames[70]="nSigmaITSpr"; // nSigmaITSpr
613
614     fCandidateVariableNames[71]="dcaLcptp"; // DCA Lc prong-to-prong
615
616     fCandidateVariableNames[72]="cosPAV0XY"; // cosPA XY x V0
617     fCandidateVariableNames[73]="cosPALcXY"; // cosPA XY x V0
618
619     fCandidateVariableNames[74]="decayLengthV0XY"; // decay length XY x V0
620     fCandidateVariableNames[75]="decayLengthLcXY"; // decay length XY x V0
621
622     fCandidateVariableNames[76]="normalizedDecayLengthV0"; // normalized decay length x V0
623     fCandidateVariableNames[77]="normalizedDecayLengthLc"; // normalized decay length x Lc
624
625     fCandidateVariableNames[78]="normalizedDecayLengthXYV0"; // normalized decay length XY x V0
626     fCandidateVariableNames[79]="normalizedDecayLengthXYLc"; // normalized decay length XY x Lc
627
628     for(Int_t ivar=0; ivar<nVar; ivar++){
629       fVariablesTree->Branch(fCandidateVariableNames[ivar].Data(),&fCandidateVariables[ivar],Form("%s/f",fCandidateVariableNames[ivar].Data()));
630     }
631     PostData(6,fVariablesTree);
632   }
633
634   return;
635 }
636 //___________________________________ hiostograms _______________________________________
637 void  AliAnalysisTaskSELc2V0bachelor::DefineHistograms() {
638
639   fCEvents = new TH1F("fCEvents","conter",17,0,17);
640   fCEvents->SetStats(kTRUE);
641   fCEvents->GetXaxis()->SetBinLabel(1,"X1");
642   fCEvents->GetXaxis()->SetBinLabel(2,"Analyzed events");
643   fCEvents->GetXaxis()->SetBinLabel(3,"AliAODVertex exists");
644   fCEvents->GetXaxis()->SetBinLabel(4,"GetNContributors()>0");
645   fCEvents->GetXaxis()->SetBinLabel(5,"MCarray exists");
646   fCEvents->GetXaxis()->SetBinLabel(6,"CascadesHF exists");
647   fCEvents->GetXaxis()->SetBinLabel(7,"MCheader exists");
648   fCEvents->GetXaxis()->SetBinLabel(8,"IsEventSelected");
649   fCEvents->GetXaxis()->SetBinLabel(9,"triggerClass!=CINT1");
650   fCEvents->GetXaxis()->SetBinLabel(10,"triggerMask!=kAnyINT");
651   fCEvents->GetXaxis()->SetBinLabel(11,"triggerMask!=kAny");
652   fCEvents->GetXaxis()->SetBinLabel(12,"vtxTitle.Contains(Z)");
653   fCEvents->GetXaxis()->SetBinLabel(13,"vtxTitle.Contains(3D)");
654   fCEvents->GetXaxis()->SetBinLabel(14,"vtxTitle.Doesn'tContain(Z-3D)");
655   fCEvents->GetXaxis()->SetBinLabel(15,Form("zVtx<=%2.0fcm",fAnalCuts->GetMaxVtxZ()));
656   fCEvents->GetXaxis()->SetBinLabel(16,"!IsEventSelected");
657   fCEvents->GetXaxis()->SetBinLabel(17,"triggerMask!=kAnyINT || triggerClass!=CINT1");
658   //fCEvents->GetXaxis()->SetTitle("");
659   fCEvents->GetYaxis()->SetTitle("counts");
660
661   fOutput->Add(fCEvents);
662   TString fillthis="";
663
664   if (fUseMCInfo) {
665     fillthis="histMcStatLc";
666     TH1F* mcStatisticLc = new TH1F(fillthis.Data(),"#Lambda_{C} generated and their decays",19,-9.5,9.5);
667     fOutput->Add(mcStatisticLc);
668   }
669
670   //fillthis="histopionV0SigmaVspTOF";
671   //TH2F *hpionV0SigmaVspTOF=new TH2F(fillthis.Data(),fillthis.Data(),300,0.,30.,100,-5.,5.);
672   fillthis="histoprotonBachSigmaVspTOF";
673   TH2F *hprotonBachSigmaVspTOF=new TH2F(fillthis.Data(),fillthis.Data(),300,0.,30.,100,-5.,5.);
674
675   //fOutput->Add(hpionV0SigmaVspTOF);
676   fOutput->Add(hprotonBachSigmaVspTOF);
677
678   //fillthis="histopionV0SigmaVspTPC";
679   //TH2F *hpionV0SigmaVspTPC=new TH2F(fillthis.Data(),fillthis.Data(),300,0.,30.,100,-5.,5.);
680   fillthis="histoprotonBachSigmaVspTPC";
681   TH2F *hprotonBachSigmaVspTPC=new TH2F(fillthis.Data(),fillthis.Data(),300,0.,30.,100,-5.,5.);
682
683   //fOutput->Add(hpionV0SigmaVspTPC);
684   fOutput->Add(hprotonBachSigmaVspTPC);
685
686   if (fUseMCInfo) {
687
688     //fillthis="histopionV0SigmaVspTOFsgn";
689     //TH2F *hpionV0SigmaVspTOFsgn=new TH2F(fillthis.Data(),fillthis.Data(),300,0.,30.,100,-5.,5.);
690     fillthis="histoprotonBachSigmaVspTOFsgn";
691     TH2F *hprotonBachSigmaVspTOFsgn=new TH2F(fillthis.Data(),fillthis.Data(),300,0.,30.,100,-5.,5.);
692
693     //fOutput->Add(hpionV0SigmaVspTOFsgn);
694     fOutput->Add(hprotonBachSigmaVspTOFsgn);
695
696     //fillthis="histopionV0SigmaVspTPCsgn";
697     //TH2F *hpionV0SigmaVspTPCsgn=new TH2F(fillthis.Data(),fillthis.Data(),300,0.,30.,100,-5.,5.);
698     fillthis="histoprotonBachSigmaVspTPCsgn";
699     TH2F *hprotonBachSigmaVspTPCsgn=new TH2F(fillthis.Data(),fillthis.Data(),300,0.,30.,100,-5.,5.);
700
701     //fOutput->Add(hpionV0SigmaVspTPCsgn);
702     fOutput->Add(hprotonBachSigmaVspTPCsgn);
703
704
705     //fillthis="histopionV0SigmaVspTOFbkg";
706     //TH2F *hpionV0SigmaVspTOFbkg=new TH2F(fillthis.Data(),fillthis.Data(),300,0.,30.,100,-5.,5.);
707     fillthis="histoprotonBachSigmaVspTOFbkg";
708     TH2F *hprotonBachSigmaVspTOFbkg=new TH2F(fillthis.Data(),fillthis.Data(),300,0.,30.,100,-5.,5.);
709
710     //fOutput->Add(hpionV0SigmaVspTOFbkg);
711     fOutput->Add(hprotonBachSigmaVspTOFbkg);
712
713     //fillthis="histopionV0SigmaVspTPCbkg";
714     //TH2F *hpionV0SigmaVspTPCbkg=new TH2F(fillthis.Data(),fillthis.Data(),300,0.,30.,100,-5.,5.);
715     fillthis="histoprotonBachSigmaVspTPCbkg";
716     TH2F *hprotonBachSigmaVspTPCbkg=new TH2F(fillthis.Data(),fillthis.Data(),300,0.,30.,100,-5.,5.);
717
718     //fOutput->Add(hpionV0SigmaVspTPCbkg);
719     fOutput->Add(hprotonBachSigmaVspTPCbkg);
720
721
722   }
723
724
725   TH1F *hZ2 = new TH1F("hZ2","",100,-50.,50.);
726   fOutput->Add(hZ2);
727   TH1F *hZ3 = new TH1F("hZ3","",100,-50.,50.);
728   fOutput->Add(hZ3);
729   TH1F *hZ4 = new TH1F("hZ4","",100,-50.,50.);
730   fOutput->Add(hZ4);
731   TH1F *hZ5 = new TH1F("hZ5","",100,-50.,50.);
732   fOutput->Add(hZ5);
733   TH1F *hZ6 = new TH1F("hZ6","",100,-50.,50.);
734   fOutput->Add(hZ6);
735   TH1F *hZ7 = new TH1F("hZ7","",100,-50.,50.);
736   fOutput->Add(hZ7);
737   TH1F *hZ8 = new TH1F("hZ8","",100,-50.,50.);
738   fOutput->Add(hZ8);
739   TH1F *hZ9 = new TH1F("hZ9","",100,-50.,50.);
740   fOutput->Add(hZ9);
741   TH1F *hZ10 = new TH1F("hZ10","",100,-50.,50.);
742   fOutput->Add(hZ10);
743   TH1F *hZ11 = new TH1F("hZ11","",100,-50.,50.);
744   fOutput->Add(hZ11);
745   TH1F *hZ12 = new TH1F("hZ12","",100,-50.,50.);
746   fOutput->Add(hZ12);
747   TH1F *hZ13 = new TH1F("hZ13","",100,-50.,50.);
748   fOutput->Add(hZ13);
749   TH1F *hZ14 = new TH1F("hZ14","",100,-50.,50.);
750   fOutput->Add(hZ14);
751   TH1F *hZ15 = new TH1F("hZ15","",100,-50.,50.);
752   fOutput->Add(hZ15);
753   TH1F *hZ16 = new TH1F("hZ16","",100,-50.,50.);
754   fOutput->Add(hZ16);
755
756   TH1I *hCandidateSelection = new TH1I("hCandidateSelection","",14,0,14);
757   hCandidateSelection->GetXaxis()->SetBinLabel(1,"IsEventSelected");
758   hCandidateSelection->GetXaxis()->SetBinLabel(2,"IsSecondaryVtx");
759   hCandidateSelection->GetXaxis()->SetBinLabel(3,"V0toPosNeg");
760   hCandidateSelection->GetXaxis()->SetBinLabel(4,"offlineV0");
761   hCandidateSelection->GetXaxis()->SetBinLabel(5,"prodCuts::kTracks");
762   hCandidateSelection->GetXaxis()->SetBinLabel(6,"prodCuts::kCandidate");
763   hCandidateSelection->GetXaxis()->SetBinLabel(7,"prodCuts::kPID");
764   hCandidateSelection->GetXaxis()->SetBinLabel(8,"prodCuts::kAll");
765   hCandidateSelection->GetXaxis()->SetBinLabel(9,"offlineV0");
766   hCandidateSelection->GetXaxis()->SetBinLabel(10,"isInFiducialAcceptance");
767   hCandidateSelection->GetXaxis()->SetBinLabel(11,"analCuts::kTracks");
768   hCandidateSelection->GetXaxis()->SetBinLabel(12,"analCuts::kCandidate");
769   hCandidateSelection->GetXaxis()->SetBinLabel(13,"analCuts::kPID");
770   hCandidateSelection->GetXaxis()->SetBinLabel(14,"analCuts::kAll");
771   fOutput->Add(hCandidateSelection);
772
773   TH1I *hEventsWithCandidates = new TH1I("hEventsWithCandidates","conter",17,0,17);
774   fOutput->Add(hEventsWithCandidates);
775
776   TH1F *hZ2a = new TH1F("hZ2a","",100,-50.,50.);
777   fOutput->Add(hZ2a);
778   TH1F *hZ3a = new TH1F("hZ3a","",100,-50.,50.);
779   fOutput->Add(hZ3a);
780   TH1F *hZ4a = new TH1F("hZ4a","",100,-50.,50.);
781   fOutput->Add(hZ4a);
782   TH1F *hZ5a = new TH1F("hZ5a","",100,-50.,50.);
783   fOutput->Add(hZ5a);
784   TH1F *hZ6a = new TH1F("hZ6a","",100,-50.,50.);
785   fOutput->Add(hZ6a);
786   TH1F *hZ7a = new TH1F("hZ7a","",100,-50.,50.);
787   fOutput->Add(hZ7a);
788   TH1F *hZ8a = new TH1F("hZ8a","",100,-50.,50.);
789   fOutput->Add(hZ8a);
790   TH1F *hZ9a = new TH1F("hZ9a","",100,-50.,50.);
791   fOutput->Add(hZ9a);
792   TH1F *hZ10a = new TH1F("hZ10a","",100,-50.,50.);
793   fOutput->Add(hZ10a);
794   TH1F *hZ11a = new TH1F("hZ11a","",100,-50.,50.);
795   fOutput->Add(hZ11a);
796   TH1F *hZ12a = new TH1F("hZ12a","",100,-50.,50.);
797   fOutput->Add(hZ12a);
798   TH1F *hZ13a = new TH1F("hZ13a","",100,-50.,50.);
799   fOutput->Add(hZ13a);
800   TH1F *hZ14a = new TH1F("hZ14a","",100,-50.,50.);
801   fOutput->Add(hZ14a);
802   TH1F *hZ15a = new TH1F("hZ15a","",100,-50.,50.);
803   fOutput->Add(hZ15a);
804   TH1F *hZ16a = new TH1F("hZ16a","",100,-50.,50.);
805   fOutput->Add(hZ16a);
806
807   TH1I *hSwitchOnCandidates1 = new TH1I("hSwitchOnCandidates1","",16,-8,8);
808   fOutput->Add(hSwitchOnCandidates1);
809   TH1I *hSwitchOnCandidates2 = new TH1I("hSwitchOnCandidates2","",16,-8,8);
810   fOutput->Add(hSwitchOnCandidates2);
811   TH1I *hSwitchOnCandidates3 = new TH1I("hSwitchOnCandidates3","",16,-8,8);
812   fOutput->Add(hSwitchOnCandidates3);
813   TH1I *hSwitchOnCandidates4 = new TH1I("hSwitchOnCandidates4","",16,-8,8);
814   fOutput->Add(hSwitchOnCandidates4);
815
816   if (fIsK0sAnalysis) DefineK0SHistos();// hK0S histos declarations
817
818   return;
819 }
820 //________________________________________________________________________
821 void AliAnalysisTaskSELc2V0bachelor::FillLc2pK0Sspectrum(AliAODRecoCascadeHF *part,
822                                                          Int_t isLc,
823                                                          Int_t &nSelectedProd,
824                                                          AliRDHFCutsLctoV0 *cutsProd,
825                                                          Int_t &nSelectedAnal,
826                                                          AliRDHFCutsLctoV0 *cutsAnal,
827                                                          TClonesArray *mcArray)
828 {
829   //
830   // Fill histos for Lc -> K0S+proton
831   //
832
833   TString fillthis="";
834
835   Double_t invmassLc = part->InvMassLctoK0sP();
836   Double_t lambdacpt = part->Pt();
837
838   AliAODv0 * v0part = (AliAODv0*)part->Getv0();
839   Bool_t onFlyV0 = v0part->GetOnFlyStatus(); // on-the-flight V0s
840   Double_t momK0s = TMath::Sqrt(v0part->Ptot2V0());
841   Double_t ptK0s = TMath::Sqrt(v0part->Pt2V0());
842   Double_t dcaV0ptp = v0part->GetDCA();
843   Double_t invmassK0s = v0part->MassK0Short();
844   Bool_t isInV0windowProd = (((cutsProd->IsSelectedSingleCut(part,AliRDHFCuts::kCandidate,2))&(AliRDHFCutsLctoV0::kLcToK0Spr))==(AliRDHFCutsLctoV0::kLcToK0Spr)); // cut on V0 invMass
845   Bool_t isInCascadeWindow = (((cutsAnal->IsSelectedSingleCut(part,AliRDHFCuts::kCandidate,0))&(AliRDHFCutsLctoV0::kLcToK0Spr))==(AliRDHFCutsLctoV0::kLcToK0Spr)); // cut on Lc->p+K0S invMass
846   Bool_t isCandidateSelectedCuts = (((cutsAnal->IsSelected(part,AliRDHFCuts::kCandidate))&(AliRDHFCutsLctoV0::kLcToK0Spr))==(AliRDHFCutsLctoV0::kLcToK0Spr)); // kinematic/topological cuts
847
848   AliAODTrack *bachelor = (AliAODTrack*)part->GetBachelor();
849   Double_t momBach  = bachelor->P();
850   Bool_t isBachelorID = (((cutsAnal->IsSelected(part,AliRDHFCuts::kPID))&(AliRDHFCutsLctoV0::kLcToK0Spr))==(AliRDHFCutsLctoV0::kLcToK0Spr)); // ID x bachelor
851
852   /*
853   if (fIsEventSelected) {
854     if ( ( !onFlyV0 ||
855            (onFlyV0 && fUseOnTheFlyV0) ) &&
856          isCandidateSelectedCuts && isBachelorID) {
857       fillthis="hist1LcMassOfflineByK0S";
858       if (isBachelorID) ((TH2F*)(fOutput->FindObject(fillthis)))->Fill(invmassLc,lambdacpt);
859     }
860   } else {
861     if ( ( !onFlyV0 ||
862            (onFlyV0 && fUseOnTheFlyV0) ) &&
863          isCandidateSelectedCuts && isBachelorID) {
864       fillthis="hist0LcMassOfflineByK0S";
865       if (isBachelorID) ((TH2F*)(fOutput->FindObject(fillthis)))->Fill(invmassLc,lambdacpt);
866     }
867     return; // don't take into account not selected events
868   }
869   */
870
871   if ( !onFlyV0 )
872     ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(3); // it counts number of candidates coming from offline V0s
873
874   if ( !( !onFlyV0 || (onFlyV0 && fUseOnTheFlyV0) ) ) return;
875
876   if ( !( ( (cutsProd->IsSelected(part,AliRDHFCuts::kTracks))&(AliRDHFCutsLctoV0::kLcToK0Spr)) == (AliRDHFCutsLctoV0::kLcToK0Spr) ) ) return;
877   ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(4);
878   if ( ( ( (cutsProd->IsSelected(part,AliRDHFCuts::kCandidate))&(AliRDHFCutsLctoV0::kLcToK0Spr)) == (AliRDHFCutsLctoV0::kLcToK0Spr) ) )
879     ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(5);
880   if ( ( ( (cutsProd->IsSelected(part,AliRDHFCuts::kPID))&(AliRDHFCutsLctoV0::kLcToK0Spr)) == (AliRDHFCutsLctoV0::kLcToK0Spr) ) )
881     ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(6);
882   if ( ( ( (cutsProd->IsSelected(part,AliRDHFCuts::kAll))&(AliRDHFCutsLctoV0::kLcToK0Spr)) == (AliRDHFCutsLctoV0::kLcToK0Spr) ) ) {
883     ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(7);
884     nSelectedProd++;
885   }
886
887
888   if ( !onFlyV0 )
889     ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(8); // it counts number of candidates coming from offline V0s
890
891   if ( cutsAnal->IsInFiducialAcceptance(part->Pt(),part->Y(4122)) )
892     ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(9);
893   if ( (((cutsAnal->IsSelected(part,AliRDHFCuts::kTracks))&(AliRDHFCutsLctoV0::kLcToK0Spr))==(AliRDHFCutsLctoV0::kLcToK0Spr)) )
894     ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(10);
895   if ( (((cutsAnal->IsSelected(part,AliRDHFCuts::kCandidate))&(AliRDHFCutsLctoV0::kLcToK0Spr))==(AliRDHFCutsLctoV0::kLcToK0Spr)) )
896     ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(11);
897   if ( (((cutsAnal->IsSelected(part,AliRDHFCuts::kPID))&(AliRDHFCutsLctoV0::kLcToK0Spr))==(AliRDHFCutsLctoV0::kLcToK0Spr)) )
898     ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(12);
899   if ( (((cutsAnal->IsSelected(part,AliRDHFCuts::kAll))&(AliRDHFCutsLctoV0::kLcToK0Spr))==(AliRDHFCutsLctoV0::kLcToK0Spr)) ) {
900     ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(13);
901     nSelectedAnal++;
902   }
903
904   if ( !(cutsAnal->IsInFiducialAcceptance(part->Pt(),part->Y(4122))) ) return;
905
906   if ( !( ( (cutsAnal->IsSelected(part,AliRDHFCuts::kTracks))&(AliRDHFCutsLctoV0::kLcToK0Spr)) == (AliRDHFCutsLctoV0::kLcToK0Spr) ) ) return;
907
908   Int_t aaa = cutsAnal->IsSelected(part,AliRDHFCuts::kTracks);
909   if ( (aaa&AliRDHFCutsLctoV0::kLcToK0Spr)==AliRDHFCutsLctoV0::kLcToK0Spr ) {
910     if ( ( (aaa&AliRDHFCutsLctoV0::kLcToLpi)==AliRDHFCutsLctoV0::kLcToLpi && bachelor->Charge()==-1)  ||
911          ( (aaa&AliRDHFCutsLctoV0::kLcToLBarpi)==AliRDHFCutsLctoV0::kLcToLBarpi && bachelor->Charge()==+1) )
912       ((TH1I*)(fOutput->FindObject("hSwitchOnCandidates1")))->Fill( -aaa );
913     else
914       ((TH1I*)(fOutput->FindObject("hSwitchOnCandidates1")))->Fill( aaa );
915   }
916
917   aaa = cutsAnal->IsSelected(part,AliRDHFCuts::kCandidate);
918   if ((aaa&AliRDHFCutsLctoV0::kLcToK0Spr)==AliRDHFCutsLctoV0::kLcToK0Spr) {
919     if ( ( (aaa&AliRDHFCutsLctoV0::kLcToLpi)==AliRDHFCutsLctoV0::kLcToLpi && bachelor->Charge()==-1) ||
920          ( (aaa&AliRDHFCutsLctoV0::kLcToLBarpi)==AliRDHFCutsLctoV0::kLcToLBarpi && bachelor->Charge()==+1) )
921       ((TH1I*)(fOutput->FindObject("hSwitchOnCandidates2")))->Fill( -aaa );
922     else
923       ((TH1I*)(fOutput->FindObject("hSwitchOnCandidates2")))->Fill( aaa );
924   }
925
926   aaa = cutsAnal->IsSelected(part,AliRDHFCuts::kPID);
927   if ((aaa&AliRDHFCutsLctoV0::kLcToK0Spr)==AliRDHFCutsLctoV0::kLcToK0Spr) {
928     if ( ( (aaa&AliRDHFCutsLctoV0::kLcToLpi)==AliRDHFCutsLctoV0::kLcToLpi && bachelor->Charge()==-1) ||
929          ( (aaa&AliRDHFCutsLctoV0::kLcToLBarpi)==AliRDHFCutsLctoV0::kLcToLBarpi && bachelor->Charge()==+1) )
930       ((TH1I*)(fOutput->FindObject("hSwitchOnCandidates3")))->Fill( -aaa );
931     else
932       ((TH1I*)(fOutput->FindObject("hSwitchOnCandidates3")))->Fill( aaa );
933   }
934
935   aaa = cutsAnal->IsSelected(part,AliRDHFCuts::kAll);
936   if ((aaa&AliRDHFCutsLctoV0::kLcToK0Spr)==AliRDHFCutsLctoV0::kLcToK0Spr) {
937     if ( ( (aaa&AliRDHFCutsLctoV0::kLcToLpi)==AliRDHFCutsLctoV0::kLcToLpi && bachelor->Charge()==-1) ||
938          ( (aaa&AliRDHFCutsLctoV0::kLcToLBarpi)==AliRDHFCutsLctoV0::kLcToLBarpi && bachelor->Charge()==+1) )
939       ((TH1I*)(fOutput->FindObject("hSwitchOnCandidates4")))->Fill( -aaa );
940     else
941       ((TH1I*)(fOutput->FindObject("hSwitchOnCandidates4")))->Fill( aaa );
942   }
943
944
945
946
947   aaa = cutsAnal->IsSelected(part,AliRDHFCuts::kCandidate);
948   Int_t flagToCheckCandidate = 0;
949   if ( (aaa&AliRDHFCutsLctoV0::kLcToK0Spr)==AliRDHFCutsLctoV0::kLcToK0Spr ) {
950     if ( aaa==AliRDHFCutsLctoV0::kLcToK0Spr ) {
951       flagToCheckCandidate = aaa; // Lc->K0S+p OK
952     } else {
953       if ( (aaa&AliRDHFCutsLctoV0::kLcToLpi)==AliRDHFCutsLctoV0::kLcToLpi ) {
954         if (bachelor->Charge()==+1)
955           flagToCheckCandidate = aaa; // Lc->Lambda+pi+
956         else if (bachelor->Charge()==-1)
957           flagToCheckCandidate =-aaa;//+(AliRDHFCutsLctoV0::kLcToK0Spr); // Lambda+pi- AS Lc->K0S+p candidate
958       }
959       if ( (aaa&AliRDHFCutsLctoV0::kLcToLBarpi)==AliRDHFCutsLctoV0::kLcToLBarpi ) {
960         if (bachelor->Charge()==-1)
961           flagToCheckCandidate = aaa; // Lc->LambdaBar+pi-
962         else if (bachelor->Charge()==+1)
963           flagToCheckCandidate =-aaa;//+(AliRDHFCutsLctoV0::kLcToK0Spr); // LambdaBar+pi+ AS Lc->K0S+p candidate
964       }
965     }
966   } else {
967     if ( aaa==AliRDHFCutsLctoV0::kLcToK0Spr ) {
968       flagToCheckCandidate = -10-(AliRDHFCutsLctoV0::kLcToK0Spr); // NEVER
969     } else {
970       if ( (aaa&AliRDHFCutsLctoV0::kLcToLpi)==AliRDHFCutsLctoV0::kLcToLpi ) {
971         if (bachelor->Charge()==+1)
972           flagToCheckCandidate = aaa; // Lc->Lambda+pi+ OK
973         else if (bachelor->Charge()==-1)
974           flagToCheckCandidate =-aaa;//+(AliRDHFCutsLctoV0::kLcToK0Spr); // Lambda+pi- AS Lc->Lambda+pi+ candidate
975       }
976       if ( (aaa&AliRDHFCutsLctoV0::kLcToLBarpi)==AliRDHFCutsLctoV0::kLcToLBarpi ) {
977         if (bachelor->Charge()==-1)
978           flagToCheckCandidate = aaa; // Lc->LambdaBar+pi- OK
979         else if (bachelor->Charge()==+1)
980           flagToCheckCandidate =-aaa;//+(AliRDHFCutsLctoV0::kLcToK0Spr); // LambdaBar+pi+ AS Lc->LambdaBar+pi- candidate
981       }
982     }
983   }
984
985
986
987   Int_t pdgCand = 4122;
988   Int_t pdgDgLctoV0bachelor[2]={3122,211};
989   Int_t pdgDgV0toDaughters[2]={2212,211};
990   Int_t isLc2LBarpi=0, isLc2Lpi=0;
991   Int_t mcLabel = 0;
992   if (fUseMCInfo) {
993     mcLabel = part->MatchToMC(pdgCand,pdgDgLctoV0bachelor[0],pdgDgLctoV0bachelor,pdgDgV0toDaughters,mcArray,kTRUE);
994     if (mcLabel>=0) {
995       if (bachelor->Charge()==-1) isLc2LBarpi=1;
996       if (bachelor->Charge()==+1) isLc2Lpi=1;
997     }
998   }
999
1000   Int_t pdgDg2prong[2] = {211, 211};
1001   Int_t labelK0S = 0;
1002   Int_t isK0S = 0;
1003   if (fUseMCInfo) {
1004     labelK0S = v0part->MatchToMC(310,mcArray,2,pdgDg2prong);
1005     if (labelK0S>=0) isK0S = 1;
1006   }
1007
1008   pdgDg2prong[0] = 211;
1009   pdgDg2prong[1] = 2212;
1010   Int_t isLambda = 0;
1011   Int_t isLambdaBar = 0;
1012   Int_t lambdaLabel = 0;
1013   if (fUseMCInfo) {
1014     lambdaLabel = v0part->MatchToMC(3122,mcArray,2,pdgDg2prong);
1015     if (lambdaLabel>=0) {
1016       AliAODMCParticle *lambdaTrack = (AliAODMCParticle*)mcArray->At(lambdaLabel);
1017       if (lambdaTrack->GetPdgCode()==3122) isLambda = 1;
1018       else if (lambdaTrack->GetPdgCode()==-3122) isLambdaBar = 1;
1019     }
1020   }
1021
1022   pdgDg2prong[0] = 11;
1023   pdgDg2prong[1] = 11;
1024   Int_t isGamma = 0;
1025   Int_t gammaLabel = 0;
1026   if (fUseMCInfo) {
1027     gammaLabel = v0part->MatchToMC(22,mcArray,2,pdgDg2prong);
1028     if (gammaLabel>=0) {
1029       AliAODMCParticle *gammaTrack = (AliAODMCParticle*)mcArray->At(gammaLabel);
1030       if (gammaTrack->GetPdgCode()==22) isGamma = 1;
1031     }
1032   }
1033
1034   Double_t invmassLc2Lpi = part->InvMassLctoLambdaPi();
1035   Double_t invmassLambda = v0part->MassLambda();
1036   Double_t invmassLambdaBar = v0part->MassAntiLambda();
1037
1038   Int_t isLcByMC = isLc+isLc2LBarpi*2+isLc2Lpi*4;
1039   Int_t isV0ByMC = isK0S+isLambdaBar*2+isLambda*4+isGamma*8;
1040
1041   Double_t nSigmaITSpr=-999.;
1042   cutsAnal->GetPidHF()->GetnSigmaITS(bachelor,4,nSigmaITSpr);
1043   Double_t nSigmaTPCpr=-999.;
1044   cutsAnal->GetPidHF()->GetnSigmaTPC(bachelor,4,nSigmaTPCpr);
1045   Double_t nSigmaTOFpr=-999.;
1046   cutsAnal->GetPidHF()->GetnSigmaTOF(bachelor,4,nSigmaTOFpr);
1047
1048   Double_t nSigmaITSpi=-999.;
1049   cutsAnal->GetPidHF()->GetnSigmaITS(bachelor,2,nSigmaITSpi);
1050   Double_t nSigmaTPCpi=-999.;
1051   cutsAnal->GetPidHF()->GetnSigmaTPC(bachelor,2,nSigmaTPCpi);
1052   Double_t nSigmaTOFpi=-999.;
1053   cutsAnal->GetPidHF()->GetnSigmaTOF(bachelor,2,nSigmaTOFpi);
1054
1055   Double_t nSigmaITSka=-999.;
1056   cutsAnal->GetPidHF()->GetnSigmaITS(bachelor,3,nSigmaITSka);
1057   Double_t nSigmaTPCka=-999.;
1058   cutsAnal->GetPidHF()->GetnSigmaTPC(bachelor,3,nSigmaTPCka);
1059   Double_t nSigmaTOFka=-999.;
1060   cutsAnal->GetPidHF()->GetnSigmaTOF(bachelor,3,nSigmaTOFka);
1061
1062
1063   // Fill candidate variable Tree (track selection, V0 invMass selection)
1064   if ( fWriteVariableTree && !onFlyV0 && isInV0windowProd && isInCascadeWindow && part->CosV0PointingAngle()>0.99) {
1065
1066     fCandidateVariables[0] = fUseMCInfo+isLcByMC; // 0: real data; 1: bkg; 2: Lc->K0S+p; 3: Lc->LambdaBar+pbar; 5: Lc->Lambda+p
1067     fCandidateVariables[1] = fUseMCInfo+isV0ByMC; // 0: real data; 1: bkg; 2: K0S->pi+pi; 3: LambdaBar->pbar+pi+; 5: Lambda->p+pi-
1068     fCandidateVariables[2] = invmassLc;
1069     fCandidateVariables[3] = invmassLc2Lpi;
1070     fCandidateVariables[4] = invmassK0s;
1071     fCandidateVariables[5] = invmassLambda;
1072     fCandidateVariables[6] = invmassLambdaBar;
1073     fCandidateVariables[7] = part->CosV0PointingAngle();
1074     fCandidateVariables[8] = dcaV0ptp;
1075     fCandidateVariables[9] = part->Getd0Prong(0);
1076     fCandidateVariables[10] = part->Getd0Prong(1);
1077     fCandidateVariables[11] = nSigmaTPCpr;
1078     fCandidateVariables[12] = nSigmaTPCpi;
1079     fCandidateVariables[13] = nSigmaTPCka;
1080     fCandidateVariables[14] = nSigmaTOFpr;
1081     fCandidateVariables[15] = nSigmaTOFpi;
1082     fCandidateVariables[16] = nSigmaTOFka;
1083     fCandidateVariables[17] = bachelor->Px();
1084     fCandidateVariables[18] = bachelor->Py();
1085     fCandidateVariables[19] = bachelor->Pz();
1086     AliAODTrack *v0neg = (AliAODTrack*)part->Getv0NegativeTrack(); 
1087     fCandidateVariables[20] = v0neg->Px();
1088     fCandidateVariables[21] = v0neg->Py();
1089     fCandidateVariables[22] = v0neg->Pz();
1090     AliAODTrack *v0pos = (AliAODTrack*)part->Getv0PositiveTrack();
1091     fCandidateVariables[23] = v0pos->Px();
1092     fCandidateVariables[24] = v0pos->Py();
1093     fCandidateVariables[25] = v0pos->Pz();
1094     fCandidateVariables[26] = part->QtProng(0);
1095     fCandidateVariables[27] = part->Alpha();
1096     fCandidateVariables[28] = v0part->Getd0Prong(0);
1097     fCandidateVariables[29] = v0part->Getd0Prong(1);
1098     fCandidateVariables[30] = part->PxProng(0);
1099     fCandidateVariables[31] = part->PyProng(0);
1100     fCandidateVariables[32] = part->PzProng(0);
1101     fCandidateVariables[33] = part->PxProng(1);
1102     fCandidateVariables[34] = part->PyProng(1);
1103     fCandidateVariables[35] = part->PzProng(1);
1104     fCandidateVariables[36] = v0part->PxProng(0);
1105     fCandidateVariables[37] = v0part->PyProng(0);
1106     fCandidateVariables[38] = v0part->PzProng(0);
1107     fCandidateVariables[39] = v0part->PxProng(1);
1108     fCandidateVariables[40] = v0part->PyProng(1);
1109     fCandidateVariables[41] = v0part->PzProng(1);
1110     fCandidateVariables[42] = flagToCheckCandidate;
1111     fCandidateVariables[43] = v0part->InvMass2Prongs(0,1,11,11);
1112
1113     fCandidateVariables[44] = bachelor->P();
1114     fCandidateVariables[45] = bachelor->Pt();
1115     fCandidateVariables[46] = v0pos->P();
1116     fCandidateVariables[47] = v0pos->Pt();
1117     fCandidateVariables[48] = v0neg->P();
1118     fCandidateVariables[49] = v0neg->Pt();
1119     fCandidateVariables[50] = part->PProng(0);
1120     fCandidateVariables[51] = part->PtProng(0);
1121     fCandidateVariables[52] = part->PProng(1);
1122     fCandidateVariables[53] = part->PtProng(1);
1123     fCandidateVariables[54] = v0part->PProng(0);
1124     fCandidateVariables[55] = v0part->PtProng(0);
1125     fCandidateVariables[56] = v0part->PProng(1);
1126     fCandidateVariables[57] = v0part->PtProng(1);
1127     fCandidateVariables[58] = part->P();
1128     fCandidateVariables[59] = part->Pt();
1129     fCandidateVariables[60] = v0part->P();
1130     fCandidateVariables[61] = v0part->Pt();
1131
1132     fCandidateVariables[62] = part->CosPointingAngle();
1133     fCandidateVariables[63] = part->DecayLength();
1134     fCandidateVariables[64] = part->DecayLengthV0();
1135
1136     fCandidateVariables[65] = part->Y(4122);
1137
1138     fCandidateVariables[66] = part->InvMass2Prongs(0,1,211,310); // D+ -> pi+ K0S
1139     fCandidateVariables[67] = part->InvMass2Prongs(0,1,321,310); // D+S -> K+ K0S
1140
1141     fCandidateVariables[68] = nSigmaITSpr;
1142     fCandidateVariables[69] = nSigmaITSpi;
1143     fCandidateVariables[70] = nSigmaITSka;
1144
1145     fCandidateVariables[71] = part->GetDCA();
1146
1147     fCandidateVariables[72] = part->CosV0PointingAngleXY();
1148     fCandidateVariables[73] = part->CosPointingAngleXY();
1149
1150     fCandidateVariables[74] = part->DecayLengthXYV0();
1151     fCandidateVariables[75] = part->DecayLengthXY();
1152
1153     fCandidateVariables[76] = part->NormalizedV0DecayLength();
1154     fCandidateVariables[77] = part->NormalizedDecayLength();
1155
1156     fCandidateVariables[78] = part->NormalizedV0DecayLengthXY();
1157     fCandidateVariables[79] = part->NormalizedDecayLengthXY();
1158
1159     Double_t v0Momentum = (v0part->PxProng(0)+v0part->PxProng(1))*(v0part->PxProng(0)+v0part->PxProng(1));
1160     v0Momentum += (v0part->PyProng(0)+v0part->PyProng(1))*(v0part->PyProng(0)+v0part->PyProng(1));
1161     v0Momentum += (v0part->PzProng(0)+v0part->PzProng(1))*(v0part->PzProng(0)+v0part->PzProng(1));
1162     v0Momentum = TMath::Sqrt(v0Momentum);
1163
1164     Double_t lcMomentum = (part->PxProng(0)+part->PxProng(1))*(part->PxProng(0)+part->PxProng(1));
1165     lcMomentum += (part->PyProng(0)+part->PyProng(1))*(part->PyProng(0)+part->PyProng(1));
1166     lcMomentum += (part->PzProng(0)+part->PzProng(1))*(part->PzProng(0)+part->PzProng(1));
1167     lcMomentum = TMath::Sqrt(lcMomentum);
1168
1169     fVariablesTree->Fill();
1170   }
1171
1172
1173
1174   if (onFlyV0 && fUseOnTheFlyV0) {  
1175
1176     fillthis="histK0SMass";
1177     ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(invmassK0s,ptK0s);
1178     if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(invmassK0s,ptK0s);
1179
1180     if (isCandidateSelectedCuts) {
1181
1182       fillthis="histpK0Svsp";
1183       ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(momBach,momK0s);
1184       if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(momBach,momK0s);
1185
1186       fillthis="histDCAtoPVvspK0S";
1187       ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(momK0s,dcaV0ptp);
1188       if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(momK0s,dcaV0ptp);
1189
1190       fillthis="histArmPodK0s";
1191       FillArmPodDistribution(v0part,fillthis,fOutputAll);
1192       if (isBachelorID) FillArmPodDistribution(v0part,fillthis,fOutputPIDBach);
1193
1194       fillthis="histLcMassByK0S";
1195       ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(invmassLc,lambdacpt);
1196       if (isBachelorID)((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(invmassLc,lambdacpt);
1197  
1198     }
1199   }
1200   else if (!onFlyV0) {
1201
1202     fillthis="histK0SMassOffline";
1203     ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(invmassK0s,ptK0s);
1204     if (isBachelorID) ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(invmassK0s,ptK0s);
1205
1206     if (isCandidateSelectedCuts) {
1207
1208       fillthis="histoprotonBachSigmaVspTOF";
1209       ((TH2F*)(fOutput->FindObject(fillthis)))->Fill(momBach,nSigmaTOFpr);
1210       fillthis="histoprotonBachSigmaVspTPC";
1211       ((TH2F*)(fOutput->FindObject(fillthis)))->Fill(momBach,nSigmaTPCpr);
1212
1213
1214       fillthis="histpK0SvspOffline";
1215       ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(momBach,momK0s);
1216       if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(momBach,momK0s);
1217
1218       fillthis="histDCAtoPVvspK0SOffline";
1219       ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(momK0s,dcaV0ptp);
1220       if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(momK0s,dcaV0ptp);
1221
1222       fillthis="histOfflineArmPodK0s";
1223       FillArmPodDistribution(v0part,fillthis,fOutputAll);
1224       if (isBachelorID) FillArmPodDistribution(v0part,fillthis,fOutputPIDBach);
1225
1226       fillthis="histLcMassOfflineByK0S";
1227       ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(invmassLc,lambdacpt);
1228       if (isBachelorID)((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(invmassLc,lambdacpt); // main histogram
1229
1230     }
1231   }
1232
1233
1234   if (fUseMCInfo) {
1235     if (isLc==1) {
1236       if (onFlyV0 && fUseOnTheFlyV0) {
1237
1238         fillthis="histK0SMassSgn";
1239         ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(invmassK0s,ptK0s);
1240         if (isBachelorID) ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(invmassK0s,ptK0s);
1241
1242         if (isCandidateSelectedCuts) {
1243
1244           fillthis="histpK0SvspSgn";
1245           ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(momBach,momK0s);
1246           if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(momBach,momK0s);
1247
1248           fillthis="histDCAtoPVvspK0SSgn";
1249           ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(momK0s,dcaV0ptp);
1250           if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(momK0s,dcaV0ptp);
1251
1252           fillthis="histArmPodK0sSgn";
1253           FillArmPodDistribution(v0part,fillthis,fOutputAll);
1254           if (isBachelorID) FillArmPodDistribution(v0part,fillthis,fOutputPIDBach);
1255
1256           fillthis="histLcMassByK0SSgn";
1257           ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(invmassLc,lambdacpt);
1258           if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(invmassLc,lambdacpt);
1259
1260         }
1261     
1262       }     
1263       else if (!onFlyV0) {  
1264
1265         fillthis="histK0SMassOfflineSgn";
1266         ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(invmassK0s,ptK0s);
1267         if (isBachelorID) ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(invmassK0s,ptK0s);
1268
1269         if (isCandidateSelectedCuts) {
1270
1271           fillthis="histoprotonBachSigmaVspTOFsgn";
1272           ((TH2F*)(fOutput->FindObject(fillthis)))->Fill(momBach,nSigmaTOFpr);
1273           fillthis="histoprotonBachSigmaVspTPCsgn";
1274           ((TH2F*)(fOutput->FindObject(fillthis)))->Fill(momBach,nSigmaTPCpr);
1275
1276
1277           fillthis="histpK0SvspOfflineSgn";
1278           ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(momBach,momK0s);
1279           if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(momBach,momK0s);
1280   
1281           fillthis="histDCAtoPVvspK0SOfflineSgn";
1282           ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(momK0s,dcaV0ptp);
1283           if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(momK0s,dcaV0ptp);
1284    
1285           fillthis="histOfflineArmPodK0sSgn";
1286           FillArmPodDistribution(v0part,fillthis,fOutputAll);
1287           if (isBachelorID) FillArmPodDistribution(v0part,fillthis,fOutputPIDBach);
1288
1289           fillthis="histLcMassOfflineByK0SSgn";
1290           ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(invmassLc,lambdacpt);
1291           if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(invmassLc,lambdacpt);
1292           
1293         }
1294
1295       }
1296
1297     }// sgn
1298     else { // bkg
1299       if (onFlyV0 && fUseOnTheFlyV0) {
1300
1301         fillthis="histK0SMassBkg";
1302         ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(invmassK0s,ptK0s);
1303         if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(invmassK0s,ptK0s);
1304
1305         if (isCandidateSelectedCuts) {
1306
1307           fillthis="histpK0SvspBkg";
1308           ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(momBach,momK0s);
1309           if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(momBach,momK0s);
1310
1311           fillthis="histDCAtoPVvspK0SBkg";
1312           ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(momK0s,dcaV0ptp);
1313           if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(momK0s,dcaV0ptp);
1314
1315           fillthis="histArmPodK0sBkg";
1316           FillArmPodDistribution(v0part,fillthis,fOutputAll);
1317           if (isBachelorID) FillArmPodDistribution(v0part,fillthis,fOutputPIDBach);
1318
1319           fillthis="histLcMassByK0SBkg";
1320           ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(invmassLc,lambdacpt);
1321           if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(invmassLc,lambdacpt);
1322  
1323         }
1324
1325       }
1326       else if (!onFlyV0) {
1327
1328         fillthis="histK0SMassOfflineBkg";
1329         ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(invmassK0s,ptK0s);
1330         if (isBachelorID) ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(invmassK0s,ptK0s);
1331   
1332         if (isCandidateSelectedCuts) {
1333
1334           fillthis="histoprotonBachSigmaVspTOFbkg";
1335           ((TH2F*)(fOutput->FindObject(fillthis)))->Fill(momBach,nSigmaTOFpr);
1336           fillthis="histoprotonBachSigmaVspTPCbkg";
1337           ((TH2F*)(fOutput->FindObject(fillthis)))->Fill(momBach,nSigmaTPCpr);
1338
1339
1340           fillthis="histpK0SvspOfflineBkg";
1341           ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(momBach,momK0s);
1342           if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(momBach,momK0s);
1343    
1344           fillthis="histDCAtoPVvspK0SOfflineBkg";
1345           ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(momK0s,dcaV0ptp);
1346           if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(momK0s,dcaV0ptp);
1347
1348           fillthis="histOfflineArmPodK0sBkg";
1349           FillArmPodDistribution(v0part,fillthis,fOutputAll);
1350           if (isBachelorID) FillArmPodDistribution(v0part,fillthis,fOutputPIDBach);
1351
1352           fillthis="histLcMassOfflineByK0SBkg";
1353           ((TH2F*)(fOutputAll->FindObject(fillthis)))->Fill(invmassLc,lambdacpt);
1354           if (isBachelorID)  ((TH2F*)(fOutputPIDBach->FindObject(fillthis)))->Fill(invmassLc,lambdacpt);
1355  
1356         }
1357
1358       }
1359
1360     }
1361   } // if fUseMCInfo
1362  
1363   return;
1364 }
1365 //-------------------------------------------------------------------------------
1366 void AliAnalysisTaskSELc2V0bachelor::MakeAnalysisForLc2prK0S(TClonesArray *arrayLctopKos,
1367                                                              TClonesArray *mcArray,
1368                                                              Int_t &nSelectedProd,
1369                                                              AliRDHFCutsLctoV0 *cutsProd,
1370                                                              Int_t &nSelectedAnal,
1371                                                              AliRDHFCutsLctoV0 *cutsAnal)
1372 {
1373
1374   // counters for efficiencies
1375   Int_t icountReco = 0;
1376
1377   //Lc prong needed to MatchToMC method
1378
1379   Int_t pdgCand = 4122;
1380   Int_t pdgDgLctoV0bachelorOld[2]={2212,310};
1381   Int_t pdgDgLctoV0bachelor[2]={310,2212};
1382   Int_t pdgDgV0toDaughters[2]={211,211};
1383
1384   // loop over cascades to search for candidates Lc->p+K0S
1385   Int_t nCascades= arrayLctopKos->GetEntriesFast();
1386   if (nCascades==0) {
1387     AliInfo("Could not find cascades, skipping the event");
1388     return;
1389   }
1390   for (Int_t iLctopK0s = 0; iLctopK0s<nCascades; iLctopK0s++) {
1391
1392     ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(0);
1393
1394     // Lc candidates and K0s from Lc
1395     AliAODRecoCascadeHF* lcK0spr = dynamic_cast<AliAODRecoCascadeHF*>(arrayLctopKos->At(iLctopK0s));
1396     if (!lcK0spr) {
1397       AliDebug(2,Form("Cascade %d doens't exist, skipping",iLctopK0s));
1398       continue;
1399     }
1400
1401     if (!lcK0spr->GetSecondaryVtx()) {
1402       AliInfo("No secondary vertex");
1403       continue;
1404     }
1405
1406     if (lcK0spr->GetNDaughters()!=2) {
1407       AliDebug(2,Form("Cascade %d has not 2 daughters (nDaughters=%d)",iLctopK0s,lcK0spr->GetNDaughters()));
1408       continue;
1409     }
1410
1411     AliAODv0 * v0part = dynamic_cast<AliAODv0*>(lcK0spr->Getv0());
1412     AliAODTrack * bachPart = dynamic_cast<AliAODTrack*>(lcK0spr->GetBachelor());
1413     if (!v0part || !bachPart) {
1414       AliDebug(2,Form("Cascade %d has no V0 or no bachelor object",iLctopK0s));
1415       continue;
1416     }
1417
1418
1419     if (!v0part->GetSecondaryVtx()) {
1420       AliDebug(2,Form("No secondary vertex for V0 by cascade %d",iLctopK0s));
1421       continue;
1422     }
1423
1424     if (v0part->GetNDaughters()!=2) {
1425       AliDebug(2,Form("current V0 has not 2 daughters (onTheFly=%d, nDaughters=%d)",v0part->GetOnFlyStatus(),v0part->GetNDaughters()));
1426       continue;
1427     }
1428
1429     AliAODTrack * v0Pos = dynamic_cast<AliAODTrack*>(lcK0spr->Getv0PositiveTrack());
1430     AliAODTrack * v0Neg = dynamic_cast<AliAODTrack*>(lcK0spr->Getv0NegativeTrack());
1431     if (!v0Neg || !v0Neg) {
1432       AliDebug(2,Form("V0 by cascade %d has no V0positive of V0negative object",iLctopK0s));
1433       continue;
1434     }
1435
1436     ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(1);
1437
1438     if (v0Pos->Charge() == v0Neg->Charge()) continue;
1439
1440     ((TH1I*)(fOutput->FindObject("hCandidateSelection")))->Fill(2);
1441
1442     Int_t isLc = 0;
1443
1444     if (fUseMCInfo) {
1445
1446       Int_t pdgCode=-2;
1447
1448       // find associated MC particle for Lc -> p+K0 and K0S->pi+pi
1449       Int_t mcLabelOld = MatchToMC(lcK0spr,pdgDgLctoV0bachelorOld,pdgDgV0toDaughters,mcArray);
1450       Int_t mcLabel = lcK0spr->MatchToMC(pdgCand,pdgDgLctoV0bachelor[0],pdgDgLctoV0bachelor,pdgDgV0toDaughters,mcArray,kTRUE);
1451       if (mcLabelOld!=mcLabel) AliDebug(2,Form(" Changed MC label: oldONE=%d wrt rightONE=%d",mcLabelOld,mcLabel));
1452       if (mcLabel>=0) {
1453         AliDebug(2,Form(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~cascade number %d (total cascade number = %d)", iLctopK0s,nCascades));
1454
1455         AliAODMCParticle *partLc = dynamic_cast<AliAODMCParticle*>(mcArray->At(mcLabel));
1456         pdgCode = partLc->GetPdgCode();
1457         if (pdgCode<0) AliDebug(2,Form(" Â¯Â¯Â¯Â¯Â¯Â¯Â¯Â¯Â¯Â¯Â¯Â¯Â¯Â¯Â¯Â¯Â¯Â¯ MClabel=%d ~~~~~~~~~~ pdgCode=%d", mcLabel, pdgCode));
1458         pdgCode = TMath::Abs(pdgCode);
1459         isLc = 1;
1460       } else {
1461         pdgCode=-1;
1462       }
1463     }
1464
1465     FillLc2pK0Sspectrum(lcK0spr, isLc,
1466                         nSelectedProd, cutsProd,
1467                         nSelectedAnal, cutsAnal,
1468                         mcArray);
1469
1470   }
1471   
1472   AliDebug(2, Form("Found %d Reco particles that are Lc!!", icountReco));
1473
1474 }
1475 //-------------------------------------------------------------------------------
1476 Int_t AliAnalysisTaskSELc2V0bachelor::MatchToMC(AliAODRecoCascadeHF *lc2bacV0,
1477                                           Int_t *pdgDgLc2bacV0, Int_t *pdgDgV0,
1478                                           TClonesArray *mcArray)
1479 {
1480
1481   // bachelor
1482   AliAODTrack *bachelor = (AliAODTrack*)lc2bacV0->GetBachelor();
1483   Int_t labBachelor = bachelor->GetLabel();
1484   if (labBachelor<0) return -1;
1485   AliAODMCParticle *partBachelor = (AliAODMCParticle*)mcArray->At(labBachelor);
1486   if (TMath::Abs(partBachelor->GetPdgCode())!=pdgDgLc2bacV0[0]) return -1;
1487
1488   Int_t labBacMother = partBachelor->GetMother();
1489   if (labBacMother<0) return -1;
1490   AliAODMCParticle *partBacMother = (AliAODMCParticle*)mcArray->At(labBacMother);
1491   if (TMath::Abs(partBacMother->GetPdgCode())!=4122) return -1;
1492
1493   // V0
1494   AliAODTrack *posV0Daugh = (AliAODTrack*)lc2bacV0->Getv0PositiveTrack();
1495   AliAODTrack *negV0Daugh = (AliAODTrack*)lc2bacV0->Getv0NegativeTrack();
1496   Int_t labV0pos = posV0Daugh->GetLabel();
1497   Int_t labV0neg = negV0Daugh->GetLabel();
1498
1499   if (labV0pos<0 || labV0neg<0) return -1;
1500   AliAODMCParticle *partV0pos = (AliAODMCParticle*)mcArray->At(labV0neg);
1501   AliAODMCParticle *partV0neg = (AliAODMCParticle*)mcArray->At(labV0pos);
1502
1503   if ( ! ( (TMath::Abs(partV0pos->GetPdgCode())==pdgDgV0[0] &&
1504             TMath::Abs(partV0neg->GetPdgCode())==pdgDgV0[1]) ||
1505            (TMath::Abs(partV0pos->GetPdgCode())==pdgDgV0[1] &&
1506             TMath::Abs(partV0neg->GetPdgCode())==pdgDgV0[0]) ) ) return -1;
1507   Int_t labV0posMother = partV0pos->GetMother();
1508   Int_t labV0negMother = partV0neg->GetMother();
1509
1510   if (labV0posMother<0 || labV0negMother<0) return -1;
1511   if (labV0posMother!=labV0negMother) return -1;
1512
1513   AliAODMCParticle *motherV0 = (AliAODMCParticle*)mcArray->At(labV0posMother);
1514
1515   if (TMath::Abs(motherV0->GetPdgCode())!=pdgDgLc2bacV0[1]) return -1;
1516   Int_t labV0mother = motherV0->GetMother();
1517   if (labV0mother<0) return -1;
1518   AliAODMCParticle *gMotherV0 = (AliAODMCParticle*)mcArray->At(labV0mother);
1519
1520   if ( !(pdgDgLc2bacV0[1]==310 && TMath::Abs(gMotherV0->GetPdgCode())==311) &&
1521        !(pdgDgLc2bacV0[1]==3122 && TMath::Abs(motherV0->GetPdgCode())==3122) ) return -1;
1522
1523   if ( (pdgDgLc2bacV0[1]==310 && TMath::Abs(gMotherV0->GetPdgCode())==311) ) {
1524     Int_t labV0GMother = gMotherV0->GetMother();
1525     if (labV0GMother<0) return -1;
1526     AliAODMCParticle *ggMotherV0 = (AliAODMCParticle*)mcArray->At(labV0GMother);
1527
1528     if (TMath::Abs(ggMotherV0->GetPdgCode())!=4122) return -1;
1529     gMotherV0 = (AliAODMCParticle*)ggMotherV0;
1530     labV0mother=labV0GMother;
1531   }
1532   else if (pdgDgLc2bacV0[1]==3122 && TMath::Abs(motherV0->GetPdgCode())==3122) {
1533     if (TMath::Abs(gMotherV0->GetPdgCode())!=4122) return -1;
1534   }
1535
1536   if (labBacMother!=labV0mother) {
1537     //AliInfo(Form(" bachelor mother label=%d - V0 mother label=%d",labBacMother, labV0mother));
1538     return -1;
1539   }
1540
1541   //AliInfo(Form(" V0: %d (label=%d) ->  %d (label=%d) + %d (label=%d) --- GM %d (PDG=%d)",
1542   //motherV0->GetPdgCode(), labV0posMother,
1543   //partV0pos->GetPdgCode(), labV0pos,
1544   //partV0neg->GetPdgCode(), labV0neg,
1545   //labV0mother, gMotherV0->GetPdgCode()));
1546
1547   //AliInfo(Form(" Bachelor: %d (label=%d) --- M %d (label=%d)",
1548   //partBachelor->GetPdgCode(), labBachelor,
1549   //labBacMother, partBacMother->GetPdgCode()));
1550   return labBacMother;//labV0mother;//
1551
1552 }
1553
1554 //________________________________________________________________
1555 Int_t AliAnalysisTaskSELc2V0bachelor::SearchLcDaughter(TClonesArray *arrayMC, Int_t iii)
1556 {
1557
1558   Int_t indexToBeReturned=-999;
1559
1560   Int_t pdgLc=4122;
1561   Int_t pdgLambda=3122;
1562   Int_t pdgV0=310;
1563   Int_t pdgK0=311;
1564   Int_t pdgBachelor=2212;
1565   Int_t pdgBachelorPi=211;
1566
1567   TString fillthis="";
1568   fillthis="histMcStatLc";
1569
1570   AliAODMCParticle *searchLc = dynamic_cast<AliAODMCParticle*>(arrayMC->At(iii));
1571   if (TMath::Abs(searchLc->GetPdgCode()) != pdgLc) return -999;
1572
1573   ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(0);
1574   indexToBeReturned = 0;
1575
1576   ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(TMath::Nint(searchLc->Charge()/3.)*1);
1577   indexToBeReturned = TMath::Nint(searchLc->Charge()/3.)*1;
1578
1579   Int_t nDaughLc = searchLc->GetNDaughters();
1580   if (nDaughLc!=2) {
1581     ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(TMath::Nint(searchLc->Charge()/3.)*10);
1582     indexToBeReturned = TMath::Nint(searchLc->Charge()/3.)*10;
1583     return indexToBeReturned;
1584   }
1585
1586   Int_t index1=searchLc->GetDaughter(0);
1587   Int_t index2=searchLc->GetDaughter(1);
1588   if (index1<=0 || index2<=0) {
1589     return -999;
1590   }
1591
1592   AliAODMCParticle *daugh1 = dynamic_cast<AliAODMCParticle*>(arrayMC->At(index1));
1593   AliAODMCParticle *daugh2 = dynamic_cast<AliAODMCParticle*>(arrayMC->At(index2));
1594   if (!daugh1 || !daugh2) return -999;
1595
1596   Int_t daughPdg1 = TMath::Abs(daugh1->GetPdgCode());
1597   Int_t daughPdg2 = TMath::Abs(daugh2->GetPdgCode());
1598   if ( !( (daughPdg1==pdgBachelor && daughPdg2==pdgK0) ||
1599           (daughPdg2==pdgBachelor && daughPdg1==pdgK0) ||
1600           (daughPdg1==pdgLambda && daughPdg2==pdgBachelorPi) ||
1601           (daughPdg2==pdgLambda && daughPdg1==pdgBachelorPi) ) ) {
1602     ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(TMath::Nint(searchLc->Charge()/3.)*10);
1603     indexToBeReturned = TMath::Nint(searchLc->Charge()/3.)*10;
1604     return indexToBeReturned;
1605   }
1606
1607   if (daughPdg1==pdgK0 || daughPdg1==pdgLambda) {
1608     index1=searchLc->GetDaughter(1);
1609     index2=searchLc->GetDaughter(0);
1610   }
1611   daugh1 = dynamic_cast<AliAODMCParticle*>(arrayMC->At(index1));
1612   daugh2 = dynamic_cast<AliAODMCParticle*>(arrayMC->At(index2));
1613   daughPdg1=TMath::Abs(daugh1->GetPdgCode());
1614   daughPdg2=TMath::Abs(daugh2->GetPdgCode());
1615
1616   if ( daughPdg1==pdgBachelor && daughPdg2==pdgK0 ) { // Lc+ -> p K0bar
1617
1618     ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(TMath::Nint(searchLc->Charge()/3.)*2);
1619     indexToBeReturned = TMath::Nint(searchLc->Charge()/3.)*2;
1620
1621     Int_t nDaughK0 = daugh2->GetNDaughters();
1622     if (nDaughK0!=1) return -999;
1623
1624     Int_t indexK0daugh=daugh2->GetDaughter(0);
1625     if (indexK0daugh<=0) return -999;
1626
1627     AliAODMCParticle *daughK0 = dynamic_cast<AliAODMCParticle*>(arrayMC->At(indexK0daugh));
1628     if (!daughK0) return -999;
1629
1630     Int_t daughK0Pdg=TMath::Abs(daughK0->GetPdgCode());
1631     if (daughK0Pdg!=pdgV0) {
1632       ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(TMath::Nint(searchLc->Charge()/3.)*4); // K0L
1633       indexToBeReturned = TMath::Nint(searchLc->Charge()/3.)*4;
1634       return indexToBeReturned;
1635     }
1636     ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(TMath::Nint(searchLc->Charge()/3.)*3); // K0S
1637     indexToBeReturned = TMath::Nint(searchLc->Charge()/3.)*3;
1638
1639     Int_t nDaughK0S = daughK0->GetNDaughters();
1640     if (nDaughK0S!=2) {
1641       ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(TMath::Nint(searchLc->Charge()/3.)*5); // other decays for K0S
1642       indexToBeReturned = TMath::Nint(searchLc->Charge()/3.)*5;
1643       return indexToBeReturned;
1644     }
1645
1646     index1=daughK0->GetDaughter(0);
1647     index2=daughK0->GetDaughter(1);
1648     if(index1<=0 || index2<=0) {
1649       return -999;
1650     }
1651
1652     AliAODMCParticle *daughK0s1 = dynamic_cast<AliAODMCParticle*>(arrayMC->At(index1));
1653     AliAODMCParticle *daughK0s2 = dynamic_cast<AliAODMCParticle*>(arrayMC->At(index2));
1654     if (!daughK0s1 || !daughK0s2) return -999;
1655
1656     Int_t daughK0s1pdg=TMath::Abs(daughK0s1->GetPdgCode());
1657     Int_t daughK0s2pdg=TMath::Abs(daughK0s2->GetPdgCode());
1658
1659     if ( daughK0s1pdg==211 && daughK0s2pdg==211 ) {
1660       ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(TMath::Nint(searchLc->Charge()/3.)*6); // K0S -> pi+ pi-
1661       indexToBeReturned = TMath::Nint(searchLc->Charge()/3.)*6;
1662     } else {
1663       ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(TMath::Nint(searchLc->Charge()/3.)*5); // other decays for K0S
1664     indexToBeReturned = TMath::Nint(searchLc->Charge()/3.)*5;
1665     }
1666
1667   } //if (daughPdg1==pdgBachelor && daughPdg2==pdgK0)
1668   else if ( daughPdg1==pdgBachelorPi && daughPdg2==pdgLambda ) { // Lc+ -> pi+ Lambda
1669
1670     ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(TMath::Nint(searchLc->Charge()/3.)*7);
1671     indexToBeReturned = TMath::Nint(searchLc->Charge()/3.)*7;
1672
1673     Int_t nDaughL = daugh2->GetNDaughters();
1674     if (nDaughL!=2) {
1675       ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(TMath::Nint(searchLc->Charge()/3.)*8);
1676       indexToBeReturned = TMath::Nint(searchLc->Charge()/3.)*8;
1677       return indexToBeReturned;
1678     }
1679
1680     index1=daugh2->GetDaughter(0);
1681     index2=daugh2->GetDaughter(1);
1682     if(index1<=0 || index2<=0) {
1683       return -999;
1684     }
1685
1686     AliAODMCParticle *daughL1 = dynamic_cast<AliAODMCParticle*>(arrayMC->At(index1));
1687     AliAODMCParticle *daughL2 = dynamic_cast<AliAODMCParticle*>(arrayMC->At(index2));
1688     if (!daughL1 || !daughL2) return -999;
1689
1690     Int_t daughL1pdg=TMath::Abs(daughL1->GetPdgCode());
1691     Int_t daughL2pdg=TMath::Abs(daughL2->GetPdgCode());
1692     if ( (daughL1pdg==211 && daughL2pdg==2212) ||
1693          (daughL2pdg==211 && daughL1pdg==2212) ) {
1694       ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(TMath::Nint(searchLc->Charge()/3.)*9);
1695       indexToBeReturned = TMath::Nint(searchLc->Charge()/3.)*9;
1696     } else {
1697       ((TH1F*)(fOutput->FindObject(fillthis)))->Fill(TMath::Nint(searchLc->Charge()/3.)*8);
1698       indexToBeReturned = TMath::Nint(searchLc->Charge()/3.)*8;
1699     }
1700
1701   } //else if (daughPdg1==pdgBachelorPi && daughPdg2==pdgLambda)
1702
1703   return indexToBeReturned;
1704
1705 }
1706 //________________________________________________________________
1707 void AliAnalysisTaskSELc2V0bachelor::FillArmPodDistribution(AliAODv0 *vZero,
1708                                                       TString histoTitle,
1709                                                       TList *histoList) {
1710
1711   Double_t alpha = vZero->AlphaV0();
1712   Double_t qT    = vZero->PtArmV0();
1713
1714   ((TH2F*)(histoList->FindObject(histoTitle)))->Fill(alpha,qT);
1715
1716 }
1717 //----------------------------------------------------
1718
1719 void AliAnalysisTaskSELc2V0bachelor::DefineK0SHistos()
1720
1721
1722   TString nameMass=" ", nameSgn=" ", nameBkg=" ";
1723
1724   ///---------------- START  K0S HISTOS DECLARATIONS -------------------///
1725
1726   if (fUseOnTheFlyV0) {
1727
1728     // V0 invariant masses (on-the-fly)
1729     nameMass="histK0SMass";
1730     TH2F* spectrumK0SMass = new TH2F(nameMass.Data(),"K^{0}_{S} invariant mass VS p_{T}; M(#pi^{+}#pi^{-}) [GeV/c^{2}]; p_{T}(K^{0}_{S}) [GeV/c]; Entries",
1731                                      520,0.43,0.56,200,0.,20.);
1732
1733     // Lc invariant masses (x K0S on-the-fly)
1734     nameMass="histLcMassByK0S";
1735     TH2F* spectrumLcMassByK0S = new TH2F(nameMass.Data(),"#Lambda_{C} invariant mass (by K^{0}_{S}) vs p_{T} ; M(#Lambda_{C}) [GeV/c^{2}]; p_{T} [GeV/c]",
1736                                          1200,2.,2.6,200,0.,20.);
1737
1738     //nameMass="histcosOAK0Spvsp";
1739     //TH2F* cosOpeningAngleK0Spvsp = new TH2F(nameMass.Data(),"#Lambda_{C}: cosine of K^{0}_{S} - p opening angle vs #Lambda_{c} momentum; Cos(Opening Angle)  ; p [GeV/c]",
1740     //200,-1.,1.,200,0.,20.);
1741
1742     nameMass="histpK0Svsp";
1743     TH2F* momentumDistributionK0Svsp = new TH2F(nameMass.Data(),"#Lambda_{C}: p(K^{0}_{S}) vs p(p);  p_{p}; p_{K^{0}_{S}}  ",
1744                                                 200,0.,20.,200,0.,20.);
1745
1746     nameMass="histArmPodK0s";
1747     TH2F* armenterosPodK0s = new TH2F(nameMass.Data(),"K^{0}_{S}: Armenteros-Podolanski distribution; #frac{p_{L}^{+}-p_{L}^{-}}{p_{L}^{+}+p_{L}^{-}}; p_{T}^{+} [GeV/c]",
1748                                       200,-1.,1.,300,0.,0.3);
1749  
1750     nameMass="histDCAtoPVvspK0S";
1751     TH2F *dcatoPVvspK0s = new TH2F(nameMass.Data(),"K^{0}_{S}: DCA to Primary Vertex vs K^{0}_{S} momentum ; p(K^{0}_{S}) [GeV/c]; DCA to Primary Vertex []; Entries",
1752                                    200,0.,20.,100,0.,10.);
1753
1754     nameMass="histK0ScosPAwrtPVvspK0s";
1755     TH2F *cosPAwrtPVvspK0s = new TH2F(nameMass.Data(),"K^{0}_{S}: cosine of pointing angle wrt primary vertex vs K^{0}_{S} momentum ; p(K^{0}_{S}) [GeV/c]; cosine; Entries",
1756                                       200,0.,20.,100,0.99,1.);
1757
1758     TH2F* allspectrumK0SMass = (TH2F*)spectrumK0SMass->Clone(); 
1759     TH2F* allspectrumLcMassByK0S    = (TH2F*)spectrumLcMassByK0S->Clone(); 
1760     //TH2F* allcosOpeningAngleK0Spvsp= (TH2F*)cosOpeningAngleK0Spvsp->Clone(); 
1761     TH2F* allmomentumDistributionK0Svsp= (TH2F*)momentumDistributionK0Svsp->Clone(); 
1762     TH2F* alldcatoPVvspK0s=(TH2F*)dcatoPVvspK0s->Clone(); 
1763     TH2F* allcosV0PAwrtPVvspK0s=(TH2F*)cosPAwrtPVvspK0s->Clone(); 
1764
1765     TH2F* pidBachspectrumK0SMass = (TH2F*)spectrumK0SMass->Clone(); 
1766     TH2F* pidBachspectrumLcMassByK0S    = (TH2F*)spectrumLcMassByK0S->Clone(); 
1767     //TH2F* pidBachcosOpeningAngleK0Spvsp= (TH2F*)cosOpeningAngleK0Spvsp->Clone(); 
1768     TH2F* pidBachmomentumDistributionK0Svsp= (TH2F*)momentumDistributionK0Svsp->Clone(); 
1769     TH2F* pidBachdcatoPVvspK0s=(TH2F*)dcatoPVvspK0s->Clone(); 
1770     TH2F* pidBachcosV0PAwrtPVvspK0s=(TH2F*)cosPAwrtPVvspK0s->Clone(); 
1771
1772     TH2F* allArmenterosPodK0s = (TH2F*)armenterosPodK0s->Clone();
1773     TH2F* pidBachArmenterosPodK0s = (TH2F*)armenterosPodK0s->Clone();
1774
1775     fOutputAll->Add(allspectrumK0SMass);
1776     fOutputAll->Add(allspectrumLcMassByK0S);
1777     //fOutputAll->Add(allcosOpeningAngleK0Spvsp); 
1778     fOutputAll->Add(allmomentumDistributionK0Svsp); 
1779     fOutputAll->Add(allArmenterosPodK0s);
1780     fOutputAll->Add(alldcatoPVvspK0s);
1781     fOutputAll->Add(allcosV0PAwrtPVvspK0s);
1782
1783     fOutputPIDBach->Add(pidBachspectrumK0SMass);
1784     fOutputPIDBach->Add(pidBachspectrumLcMassByK0S);
1785     //fOutputPIDBach->Add(pidBachcosOpeningAngleK0Spvsp); 
1786     fOutputPIDBach->Add(pidBachmomentumDistributionK0Svsp); 
1787     fOutputPIDBach->Add(pidBachArmenterosPodK0s);
1788     fOutputPIDBach->Add(pidBachdcatoPVvspK0s);
1789     fOutputPIDBach->Add(pidBachcosV0PAwrtPVvspK0s);
1790  
1791   }
1792
1793   // V0 invariant masses (offline)
1794   nameMass="histK0SMassOffline";
1795   TH2F* spectrumK0SMassOffline = new TH2F(nameMass.Data(),"K^{0}_{S} invariant mass VS p_{T}; M(#pi^{+}#pi^{-}) [GeV/c^{2}]; p_{T}(K^{0}_{S}) [GeV/c]; Entries",
1796                                           520,0.43,0.56,200,0.,20.);
1797
1798   // Lc invariant masses (x K0S offline)
1799   nameMass="histLcMassOfflineByK0S";
1800   TH2F* spectrumLcMassOfflineByK0S = new TH2F(nameMass.Data(),"#Lambda_{C} invariant mass (by K^{0}_{S}) vs p_{T}; M(K^{0}_{S}p) [GeV/c^{2}]; p_{T} [GeV/c]",
1801                                               1200,2.,2.6,200,0.,20.);
1802
1803
1804   //nameMass="histcosOAK0SpvspOffline";
1805   //TH2F* cosOpeningAngleK0SpvspOffline = new TH2F(nameMass.Data(),"#Lambda_{C}: K^{0}_{S} - p opening angle vs p  -  Offline ; Cos(Opening Angle)  ; p [GeV/c]",
1806   //200,-1.,1.,200,0.,20.);
1807
1808   nameMass="histpK0SvspOffline";
1809   TH2F* momentumDistributionK0SvspOffline = new TH2F(nameMass.Data(),"#Lambda_{C}: p(K^{0}_{S}) vs p(p) - Offline ;  p_{p} [GeV/c]; p_{K^{0}_{S}} [GeV/c]",
1810                                                     200,0.,20.,200,0.,20.);
1811
1812   nameMass="histOfflineArmPodK0s";
1813   TH2F* armenterosPodK0sOff = new TH2F(nameMass.Data(),"K^{0}_{S}  Armenteros-Podolanski distribution - Offline; #frac{p_{L}^{+}-p_{L}^{-}}{p_{L}^{+}+p_{L}^{-}}; p_{T}^{+} [GeV/c]",
1814                                        200,-1.,1.,300,0.,0.3);
1815
1816   nameMass="histDCAtoPVvspK0SOffline";
1817   TH2F *dcatoPVvspK0sOffline = new TH2F(nameMass.Data(),"K^{0}_{S}: DCA to Primary Vertex vs  K^{0}_{S} invariant mass - Offline; p(K^{0}_{S}) [GeV/c]; DCA to Primary Vertex []; Entries",
1818                                         200,0.,20.,100,0.,10.);
1819
1820   nameMass="histK0ScosPAwrtPVvspK0sOffline";
1821   TH2F *cosPAwrtPVvspK0sOffline = new TH2F(nameMass.Data(),"K^{0}_{S}: cosine of pointing angle wrt primary vertex vs K^{0}_{S} momentum - Offline; p(K^{0}_{S}) [GeV/c]; cosine; Entries",
1822                                            200,0.,20.,100,0.99,1.);
1823
1824
1825
1826   TH2F* allspectrumK0SMassOffline = (TH2F*)spectrumK0SMassOffline->Clone(); 
1827   TH2F* allspectrumLcMassOfflineByK0S    = (TH2F*)spectrumLcMassOfflineByK0S->Clone(); 
1828   //TH2F* allcosOpeningAngleK0SpvspOffline= (TH2F*)cosOpeningAngleK0SpvspOffline->Clone(); 
1829   TH2F* allmomentumDistributionK0SvspOffline= (TH2F*)momentumDistributionK0SvspOffline->Clone(); 
1830   TH2F* alldcatoPVvspK0sOffline=(TH2F*)dcatoPVvspK0sOffline->Clone(); 
1831   TH2F* allcosPAwrtPVvspK0sOffline=(TH2F*)cosPAwrtPVvspK0sOffline->Clone(); 
1832
1833   TH2F* pidBachspectrumK0SMassOffline = (TH2F*)spectrumK0SMassOffline->Clone(); 
1834   TH2F* pidBachspectrumLcMassOfflineByK0S    = (TH2F*)spectrumLcMassOfflineByK0S->Clone(); 
1835   //TH2F* pidBachcosOpeningAngleK0SpvspOffline= (TH2F*)cosOpeningAngleK0SpvspOffline->Clone(); 
1836   TH2F* pidBachmomentumDistributionK0SvspOffline= (TH2F*)momentumDistributionK0SvspOffline->Clone(); 
1837   TH2F* pidBachdcatoPVvspK0sOffline=(TH2F*)dcatoPVvspK0sOffline->Clone(); 
1838   TH2F* pidBachcosPAwrtPVvspK0sOffline=(TH2F*)cosPAwrtPVvspK0sOffline->Clone(); 
1839
1840   TH2F* allArmenterosPodK0sOff = (TH2F*)armenterosPodK0sOff->Clone();
1841   TH2F* pidBachArmenterosPodK0sOff = (TH2F*)armenterosPodK0sOff->Clone();
1842
1843
1844   fOutputAll->Add(allspectrumK0SMassOffline);
1845   fOutputAll->Add(allspectrumLcMassOfflineByK0S);
1846   //fOutputAll->Add(allcosOpeningAngleK0SpvspOffline); 
1847   fOutputAll->Add(allmomentumDistributionK0SvspOffline); 
1848   fOutputAll->Add(allArmenterosPodK0sOff);
1849   fOutputAll->Add(alldcatoPVvspK0sOffline);
1850   fOutputAll->Add(allcosPAwrtPVvspK0sOffline);
1851
1852   fOutputPIDBach->Add(pidBachspectrumK0SMassOffline);
1853   fOutputPIDBach->Add(pidBachspectrumLcMassOfflineByK0S);
1854   //fOutputPIDBach->Add(pidBachcosOpeningAngleK0SpvspOffline); 
1855   fOutputPIDBach->Add(pidBachmomentumDistributionK0SvspOffline); 
1856   fOutputPIDBach->Add(pidBachArmenterosPodK0sOff);
1857   fOutputPIDBach->Add(pidBachdcatoPVvspK0sOffline);
1858   fOutputPIDBach->Add(pidBachcosPAwrtPVvspK0sOffline);
1859
1860   /*
1861   nameMass="hist1LcMassOfflineByK0S";
1862   TH2D* h1 = new TH2D(nameMass.Data(),"IsEventSelected; M(#Lambda_{C}) [GeV/c^{2}]; p_{T}",1200,2.,2.6,200,0.,20.);
1863   fOutput->Add(h1);
1864   nameMass="hist0LcMassOfflineByK0S";
1865   TH2D* h0 = new TH2D(nameMass.Data(),"!IsEventSelected; M(#Lambda_{C}) [GeV/c^{2}]; p_{T}",1200,2.,2.6,200,0.,20.);
1866   fOutput->Add(h0);
1867   */
1868
1869   if (fUseMCInfo) {
1870
1871     if (fUseOnTheFlyV0) {
1872
1873       nameSgn="histK0SMassSgn";
1874       nameBkg="histK0SMassBkg";
1875       TH2F* spectrumK0SMassSgn = new TH2F(nameSgn.Data(), "K^{0}_{S} Signal invariant mass VS p_{T} - MC; M(K^{0}_{S}) [GeV/c^{2}]; p_{T}(K^{0}_{S}) [GeV/c]; Entries", 520,0.43,0.56,200,0.,20.);
1876       TH2F* spectrumK0SMassBkg = new TH2F(nameBkg.Data(), "K^{0}_{S} Background invariant mass VS p_{T} - MC; M(K^{0}_{S}) [GeV/c^{2}]; p_{T}(K^{0}_{S}) [GeV/c]; Entries",  520,0.43,0.56,200,0.,20.);
1877
1878       TH2F* allspectrumK0SMassSgn = (TH2F*)spectrumK0SMassSgn->Clone(); 
1879       TH2F* allspectrumK0SMassBkg = (TH2F*) spectrumK0SMassBkg->Clone();  
1880       TH2F* pidBachspectrumK0SMassSgn = (TH2F*)spectrumK0SMassSgn->Clone(); 
1881       TH2F* pidBachspectrumK0SMassBkg = (TH2F*) spectrumK0SMassBkg->Clone();  
1882   
1883
1884       fOutputAll->Add(allspectrumK0SMassSgn);
1885       fOutputAll->Add(allspectrumK0SMassBkg);
1886       fOutputPIDBach->Add(pidBachspectrumK0SMassSgn);
1887       fOutputPIDBach->Add(pidBachspectrumK0SMassBkg);
1888
1889
1890       nameSgn="histLcMassByK0SSgn";
1891       nameBkg="histLcMassByK0SBkg";
1892       TH2F* spectrumLcMassByK0SSgn = new TH2F(nameSgn.Data(), "#Lambda_{C} Signal invariant mass (by K^{0}_{S}) vs p_{T}  - MC; M(#Lambda_{C}) [GeV/c^{2}];  p_{T}",
1893                                               1200,2.,2.6,200,0.,20.);
1894       TH2F* spectrumLcMassByK0SBkg = new TH2F(nameBkg.Data(), "#Lambda_{C} Background invariant mass (by K^{0}_{S}) vs p_{T}  - MC; M(#Lambda_{C}) [GeV/c^{2}]; p_{T}",
1895                                               1200,2.,2.6,200,0.,20.);
1896
1897       TH2F* allspectrumLcMassByK0SSgn = (TH2F*)spectrumLcMassByK0SSgn->Clone(); 
1898       TH2F* allspectrumLcMassByK0SBkg = (TH2F*) spectrumLcMassByK0SBkg->Clone();  
1899       TH2F* pidBachspectrumLcMassByK0SSgn = (TH2F*)spectrumLcMassByK0SSgn->Clone(); 
1900       TH2F* pidBachspectrumLcMassByK0SBkg = (TH2F*) spectrumLcMassByK0SBkg->Clone();  
1901       fOutputAll->Add(allspectrumLcMassByK0SSgn);
1902       fOutputAll->Add(allspectrumLcMassByK0SBkg);
1903       fOutputPIDBach->Add(pidBachspectrumLcMassByK0SSgn);
1904       fOutputPIDBach->Add(pidBachspectrumLcMassByK0SBkg);
1905
1906       /*
1907       nameSgn="histcosOAK0SpSgnvsp";
1908       nameBkg="histcosOAK0SpBkgvsp";
1909       TH2F* cosOpeningAngleK0SpSgnvsp= new TH2F(nameSgn.Data(),"#Lambda_{C} SGN : K^{0}_{S} - p Opening Angle  vs p - MC ; Cos(Opening Angle);  p ",
1910                                                 200,-1.,1.,200,0.,20.);
1911       TH2F* cosOpeningAngleK0SpBkgvsp= new TH2F(nameBkg.Data(),"#Lambda_{C} BKG : K^{0}_{S} - p Opening Angle  vs p - MC;  Cos(Opening Angle);  p ",
1912                                                 200,-1.,1.,200,0.,20.);
1913
1914       TH2F* allcosOpeningAngleK0SpSgnvsp= (TH2F*)cosOpeningAngleK0SpSgnvsp->Clone(); 
1915       TH2F* allcosOpeningAngleK0SpBkgvsp= (TH2F*)cosOpeningAngleK0SpBkgvsp->Clone(); 
1916       TH2F* pidBachcosOpeningAngleK0SpSgnvsp= (TH2F*)cosOpeningAngleK0SpSgnvsp->Clone(); 
1917       TH2F* pidBachcosOpeningAngleK0SpBkgvsp= (TH2F*)cosOpeningAngleK0SpBkgvsp->Clone(); 
1918       fOutputAll->Add(allcosOpeningAngleK0SpSgnvsp); 
1919       fOutputAll->Add(allcosOpeningAngleK0SpBkgvsp); 
1920       fOutputPIDBach->Add(pidBachcosOpeningAngleK0SpSgnvsp); 
1921       fOutputPIDBach->Add(pidBachcosOpeningAngleK0SpBkgvsp); 
1922       */
1923
1924       nameSgn="histpK0SvspSgn";
1925       nameBkg="histpK0SvspBkg";
1926       TH2F* momentumDistributionK0SvspSgn= new TH2F(nameSgn.Data(),"#Lambda_{C} SGN : K^{0}_{S} vs p Total Momentum Distribution - MC; p_{p}; p_{K^{0}_{S}}",
1927                                                     200,0.,20.,200,0.,20.);
1928       TH2F* momentumDistributionK0SvspBkg= new TH2F(nameBkg.Data(),"#Lambda_{C} BKG : K^{0}_{S} vs p Total Momentum Distribution - MC; p_{p}; p_{K^{0}_{S}}",
1929                                                     200,0.,20.,200,0.,20.);
1930
1931       TH2F* allmomentumDistributionK0SvspSgn= (TH2F*)momentumDistributionK0SvspSgn->Clone(); 
1932       TH2F* allmomentumDistributionK0SvspBkg= (TH2F*)momentumDistributionK0SvspBkg->Clone(); 
1933       TH2F* pidBachmomentumDistributionK0SvspSgn= (TH2F*)momentumDistributionK0SvspSgn->Clone(); 
1934       TH2F* pidBachmomentumDistributionK0SvspBkg= (TH2F*)momentumDistributionK0SvspBkg->Clone(); 
1935       fOutputAll->Add(allmomentumDistributionK0SvspSgn); 
1936       fOutputAll->Add(allmomentumDistributionK0SvspBkg); 
1937       fOutputPIDBach->Add(pidBachmomentumDistributionK0SvspSgn); 
1938       fOutputPIDBach->Add(pidBachmomentumDistributionK0SvspBkg); 
1939
1940
1941       // armenteros-podolanski plots K0S
1942       nameSgn="histArmPodK0sSgn";
1943       nameBkg="histArmPodK0sBkg";
1944       TH2F* armenterosPodK0sSgn = new TH2F(nameSgn.Data(),"K^{0}_{S}  Armenteros-Podolanski distribution (sgn); #frac{p_{L}^{+}-p_{L}^{-}}{p_{L}^{+}+p_{L}^{-}}; p_{T}^{+} [GeV/c]",
1945                                            200,-1.,1.,300,0.,0.3);
1946       TH2F* armenterosPodK0sBkg = new TH2F(nameBkg.Data(),"K^{0}_{S}  Armenteros-Podolanski distribution (bkg); #frac{p_{L}^{+}-p_{L}^{-}}{p_{L}^{+}+p_{L}^{-}}; p_{T}^{+} [GeV/c]",
1947                                            200,-1.,1.,300,0.,0.3);
1948
1949       TH2F* allArmenterosPodK0sSgn = (TH2F*)armenterosPodK0sSgn->Clone();
1950       TH2F* allArmenterosPodK0sBkg = (TH2F*)armenterosPodK0sBkg->Clone();
1951       TH2F* pidBachArmenterosPodK0sSgn = (TH2F*)armenterosPodK0sSgn->Clone();
1952       TH2F* pidBachArmenterosPodK0sBkg = (TH2F*)armenterosPodK0sBkg->Clone();
1953
1954       fOutputAll->Add(allArmenterosPodK0sSgn);
1955       fOutputAll->Add(allArmenterosPodK0sBkg);
1956
1957       fOutputPIDBach->Add(pidBachArmenterosPodK0sSgn);
1958       fOutputPIDBach->Add(pidBachArmenterosPodK0sBkg);
1959
1960
1961       nameSgn="histDCAtoPVvspK0SSgn";
1962       nameBkg="histDCAtoPVvspK0SBkg";
1963       TH2F *dcatoPVvspK0sSgn=new TH2F(nameSgn.Data(),"K^{0}_{S}: DCA to Primary Vertex vs  K^{0}_{S} invariant mass (sgn); p(K^{0}_{S}) [GeV/c]; DCA to Primary Vertex []; Entries",200,0.,20.,100,0.,10.0);
1964       TH2F *dcatoPVvspK0sBkg=new TH2F(nameBkg.Data(),"K^{0}_{S}: DCA to Primary Vertex vs  K^{0}_{S} invariant mass (bkg); p(K^{0}_{S}) [GeV/c]; DCA to Primary Vertex []; Entries",200,0.,20.,100,0.,10.0);
1965
1966       TH2F* alldcatoPVvspK0sSgn= (TH2F*)dcatoPVvspK0sSgn->Clone();
1967       TH2F* alldcatoPVvspK0sBkg= (TH2F*)dcatoPVvspK0sBkg->Clone();
1968       TH2F* pidBachdcatoPVvspK0sSgn= (TH2F*)dcatoPVvspK0sSgn->Clone();
1969       TH2F* pidBachdcatoPVvspK0sBkg= (TH2F*)dcatoPVvspK0sBkg->Clone();
1970
1971       fOutputAll->Add(alldcatoPVvspK0sSgn);
1972       fOutputPIDBach->Add(pidBachdcatoPVvspK0sSgn);
1973       fOutputAll->Add(alldcatoPVvspK0sBkg);
1974       fOutputPIDBach->Add(pidBachdcatoPVvspK0sBkg);
1975
1976     }
1977
1978
1979     nameSgn="histK0SMassOfflineSgn";
1980     nameBkg="histK0SMassOfflineBkg";
1981     TH2F* spectrumK0SMassOfflineSgn = new TH2F(nameSgn.Data(), "K^{0}_{S} Signal invariant mass VS p_{T} - MC; M(K^{0}_{S}) [GeV/c^{2}]; p_{T}(K^{0}_{S}) [GeV/c]; Entries",
1982                                                520,0.43,0.56,200,0.,20.);
1983     TH2F* spectrumK0SMassOfflineBkg = new TH2F(nameBkg.Data(), "K^{0}_{S} Background invariant mass VS p_{T} - MC; M(K^{0}_{S}) [GeV/c^{2}]; p_{T}(K^{0}_{S}) [GeV/c]; Entries",
1984                                                520,0.43,0.56,200,0.,20.);
1985
1986     TH2F* allspectrumK0SMassOfflineSgn = (TH2F*)spectrumK0SMassOfflineSgn->Clone(); 
1987     TH2F* allspectrumK0SMassOfflineBkg = (TH2F*) spectrumK0SMassOfflineBkg->Clone();  
1988     fOutputAll->Add(allspectrumK0SMassOfflineSgn);
1989     fOutputAll->Add(allspectrumK0SMassOfflineBkg);
1990
1991
1992     TH2F* pidBachspectrumK0SMassOfflineSgn = (TH2F*)spectrumK0SMassOfflineSgn->Clone(); 
1993     TH2F* pidBachspectrumK0SMassOfflineBkg = (TH2F*) spectrumK0SMassOfflineBkg->Clone();
1994     fOutputPIDBach->Add(pidBachspectrumK0SMassOfflineSgn);
1995     fOutputPIDBach->Add(pidBachspectrumK0SMassOfflineBkg);
1996
1997
1998     nameSgn="histLcMassOfflineByK0SSgn";
1999     nameBkg="histLcMassOfflineByK0SBkg";
2000     TH2F* spectrumLcMassOfflineByK0SSgn = new TH2F(nameSgn.Data(), "#Lambda_{C} Signal invariant mass (by K^{0}_{S})  vs p_{T} - MC; M(#Lambda_{C}) [GeV/c^{2}]; p_{T}",
2001                                                    1200,2.,2.6,200,0.,20.);
2002     TH2F* spectrumLcMassOfflineByK0SBkg = new TH2F(nameBkg.Data(), "#Lambda_{C} Background invariant mass (by K^{0}_{S})  vs p_{T} - MC; M(#Lambda_{C}) [GeV/c^{2}]; p_{T}",
2003                                                    1200,2.,2.6,200,0.,20.);
2004
2005
2006     TH2F* allspectrumLcMassOfflineByK0SSgn = (TH2F*)spectrumLcMassOfflineByK0SSgn->Clone(); 
2007     TH2F* allspectrumLcMassOfflineByK0SBkg = (TH2F*) spectrumLcMassOfflineByK0SBkg->Clone();  
2008     TH2F* pidBachspectrumLcMassOfflineByK0SSgn = (TH2F*)spectrumLcMassOfflineByK0SSgn->Clone(); 
2009     TH2F* pidBachspectrumLcMassOfflineByK0SBkg = (TH2F*) spectrumLcMassOfflineByK0SBkg->Clone();  
2010     fOutputAll->Add(allspectrumLcMassOfflineByK0SSgn);
2011     fOutputAll->Add(allspectrumLcMassOfflineByK0SBkg);
2012     fOutputPIDBach->Add(pidBachspectrumLcMassOfflineByK0SSgn);
2013     fOutputPIDBach->Add(pidBachspectrumLcMassOfflineByK0SBkg);
2014   
2015  
2016
2017     /*
2018     nameSgn="histcosOAK0SpSgnvspOffline";
2019     nameBkg="histcosOAK0SpBkgvspOffline";
2020     TH2F* cosOpeningAngleK0SpSgnvspOffline= new TH2F(nameSgn.Data(),"#Lambda_{C} SGN : K^{0}_{S} - p Opening Angle  vs p  -  Offline  - MC ; Cos(Opening Angle);  p ",
2021                                                      200,-1.,1.,200,0.,20.);
2022     TH2F* cosOpeningAngleK0SpBkgvspOffline= new TH2F(nameBkg.Data(),"#Lambda_{C} BKG : K^{0}_{S} - p Opening Angle  vs p  -  Offline  - MC;  Cos(Opening Angle);  p ",
2023                                                      200,-1.,1.,200,0.,20.);
2024     
2025
2026     TH2F* allcosOpeningAngleK0SpSgnvspOffline= (TH2F*)cosOpeningAngleK0SpSgnvspOffline->Clone(); 
2027     TH2F* allcosOpeningAngleK0SpBkgvspOffline= (TH2F*)cosOpeningAngleK0SpBkgvspOffline->Clone(); 
2028     TH2F* pidBachcosOpeningAngleK0SpSgnvspOffline= (TH2F*)cosOpeningAngleK0SpSgnvspOffline->Clone(); 
2029     TH2F* pidBachcosOpeningAngleK0SpBkgvspOffline= (TH2F*)cosOpeningAngleK0SpBkgvspOffline->Clone(); 
2030     fOutputAll->Add(allcosOpeningAngleK0SpSgnvspOffline); 
2031     fOutputAll->Add(allcosOpeningAngleK0SpBkgvspOffline); 
2032     fOutputPIDBach->Add(pidBachcosOpeningAngleK0SpSgnvspOffline); 
2033     fOutputPIDBach->Add(pidBachcosOpeningAngleK0SpBkgvspOffline); 
2034     */
2035
2036
2037
2038     nameSgn="histpK0SvspOfflineSgn";
2039     nameBkg="histpK0SvspOfflineBkg";
2040     TH2F* momentumDistributionK0SvspOfflineSgn= new TH2F(nameSgn.Data(),"#Lambda_{C} SGN : K^{0}_{S} vs p Total Momentum Distribution - Offline  - MC; p_{p};  p_{K^{0}_{S}}",
2041                                                          200,0.,20.,200,0.,20.);
2042     TH2F* momentumDistributionK0SvspOfflineBkg= new TH2F(nameBkg.Data(),"#Lambda_{C} BKG : K^{0}_{S} vs p Total Momentum Distribution - Offline  - MC;  p_{p}; p_{K^{0}_{S}}",
2043                                                          200,0.,20.,200,0.,20.);
2044
2045
2046     TH2F* allmomentumDistributionK0SvspOfflineSgn= (TH2F*)momentumDistributionK0SvspOfflineSgn->Clone(); 
2047     TH2F* allmomentumDistributionK0SvspOfflineBkg= (TH2F*)momentumDistributionK0SvspOfflineBkg->Clone(); 
2048     TH2F* pidBachmomentumDistributionK0SvspOfflineSgn= (TH2F*)momentumDistributionK0SvspOfflineSgn->Clone(); 
2049     TH2F* pidBachmomentumDistributionK0SvspOfflineBkg= (TH2F*)momentumDistributionK0SvspOfflineBkg->Clone(); 
2050     fOutputAll->Add(allmomentumDistributionK0SvspOfflineSgn); 
2051     fOutputAll->Add(allmomentumDistributionK0SvspOfflineBkg); 
2052     fOutputPIDBach->Add(pidBachmomentumDistributionK0SvspOfflineSgn); 
2053     fOutputPIDBach->Add(pidBachmomentumDistributionK0SvspOfflineBkg); 
2054
2055
2056
2057
2058
2059     // armenteros-podolanski plots K0S (offline)
2060     nameSgn="histOfflineArmPodK0sSgn";
2061     nameBkg="histOfflineArmPodK0sBkg";
2062     TH2F* armenterosPodK0sOffSgn = new TH2F(nameSgn.Data(),"K^{0}_{S}  Armenteros-Podolanski distribution (sgn) -offline-; #frac{p_{L}^{+}-p_{L}^{-}}{p_{L}^{+}+p_{L}^{-}}; p_{T}^{+} [GeV/c]",200,-1.,1.,300,0.,0.3);
2063     TH2F* armenterosPodK0sOffBkg = new TH2F(nameBkg.Data(),"K^{0}_{S}  Armenteros-Podolanski distribution (bkg) -offline-; #frac{p_{L}^{+}-p_{L}^{-}}{p_{L}^{+}+p_{L}^{-}}; p_{T}^{+} [GeV/c]",200,-1.,1.,300,0.,0.3);
2064   
2065
2066     TH2F* allArmenterosPodK0sOffSgn = (TH2F*)armenterosPodK0sOffSgn->Clone();
2067     TH2F* allArmenterosPodK0sOffBkg = (TH2F*)armenterosPodK0sOffBkg->Clone();
2068     TH2F* pidBachArmenterosPodK0sOffSgn = (TH2F*)armenterosPodK0sOffSgn->Clone();
2069     TH2F* pidBachArmenterosPodK0sOffBkg = (TH2F*)armenterosPodK0sOffBkg->Clone();
2070
2071
2072     fOutputAll->Add(allArmenterosPodK0sOffSgn);
2073     fOutputAll->Add(allArmenterosPodK0sOffBkg);
2074     fOutputPIDBach->Add(pidBachArmenterosPodK0sOffSgn);
2075     fOutputPIDBach->Add(pidBachArmenterosPodK0sOffBkg);
2076
2077
2078     nameSgn="histDCAtoPVvspK0SOfflineSgn";
2079     nameBkg="histDCAtoPVvspK0SOfflineBkg";
2080     TH2F *dcatoPVvspK0sOfflineSgn=new TH2F(nameSgn.Data(),"K^{0}_{S}: DCA to Primary Vertex vs  K^{0}_{S} invariant mass  -offline - (sgn); p(K^{0}_{S}) [GeV/c]; DCA to Primary Vertex []; Entries",200,0.,20.,100,0.,10.0);
2081     TH2F *dcatoPVvspK0sOfflineBkg=new TH2F(nameBkg.Data(),"K^{0}_{S}: DCA to Primary Vertex vs  K^{0}_{S} invariant mass  -offline - (bkg); p(K^{0}_{S}) [GeV/c]; DCA to Primary Vertex []; Entries",200,0.,20.,100,0.,10.0);
2082     
2083
2084     TH2F* alldcatoPVvspK0sOfflineSgn= (TH2F*)dcatoPVvspK0sOfflineSgn->Clone();
2085     TH2F* pidBachdcatoPVvspK0sOfflineSgn= (TH2F*)dcatoPVvspK0sOfflineSgn->Clone();
2086     TH2F* alldcatoPVvspK0sOfflineBkg= (TH2F*)dcatoPVvspK0sOfflineBkg->Clone();
2087     TH2F* pidBachdcatoPVvspK0sOfflineBkg= (TH2F*)dcatoPVvspK0sOfflineBkg->Clone();
2088
2089
2090
2091     fOutputAll->Add(alldcatoPVvspK0sOfflineSgn);
2092     fOutputPIDBach->Add(pidBachdcatoPVvspK0sOfflineSgn);
2093     fOutputAll->Add(alldcatoPVvspK0sOfflineBkg);
2094     fOutputPIDBach->Add(pidBachdcatoPVvspK0sOfflineBkg);
2095
2096   }
2097
2098
2099   ///---------------- END  K0S HISTOS DECLARATIONS -------------------///
2100 }