From 42c76bea45a72cfc8311a06ebf415c01eb9d2999 Mon Sep 17 00:00:00 2001 From: jbook Date: Thu, 6 Mar 2014 21:40:48 +0100 Subject: [PATCH] allow for internal trains --- .../AliAnalysisTaskMultiDielectron.cxx | 59 +++++++- .../AliAnalysisTaskMultiDielectron.h | 3 +- .../AliAnalysisTaskMultiDielectronTG.cxx | 5 +- PWGDQ/dielectron/AliDielectron.cxx | 130 +++++++++++++++++- PWGDQ/dielectron/AliDielectron.h | 13 +- .../dielectron/AliDielectronMixingHandler.cxx | 21 +-- PWGDQ/dielectron/AliDielectronMixingHandler.h | 2 +- PWGDQ/dielectron/AliDielectronPairLegCuts.cxx | 4 + 8 files changed, 214 insertions(+), 23 deletions(-) diff --git a/PWGDQ/dielectron/AliAnalysisTaskMultiDielectron.cxx b/PWGDQ/dielectron/AliAnalysisTaskMultiDielectron.cxx index 78943c0d949..1d6e3b6508f 100644 --- a/PWGDQ/dielectron/AliAnalysisTaskMultiDielectron.cxx +++ b/PWGDQ/dielectron/AliAnalysisTaskMultiDielectron.cxx @@ -44,6 +44,7 @@ ClassImp(AliAnalysisTaskMultiDielectron) //_________________________________________________________________________________ AliAnalysisTaskMultiDielectron::AliAnalysisTaskMultiDielectron() : AliAnalysisTaskSE(), + fPairArray(0x0), fListDielectron(), fListHistos(), fListCF(), @@ -68,6 +69,7 @@ AliAnalysisTaskMultiDielectron::AliAnalysisTaskMultiDielectron() : //_________________________________________________________________________________ AliAnalysisTaskMultiDielectron::AliAnalysisTaskMultiDielectron(const char *name) : AliAnalysisTaskSE(name), + fPairArray(0x0), fListDielectron(), fListHistos(), fListCF(), @@ -110,7 +112,8 @@ AliAnalysisTaskMultiDielectron::~AliAnalysisTaskMultiDielectron() //lists need to be owner... fListHistos.SetOwner(kFALSE); fListCF.SetOwner(kFALSE); - + + // if(fPairArray) { delete fPairArray; fPairArray=0; } // try to reduce memory issues if(fEventStat) { delete fEventStat; fEventStat=0; } if(fTriggerAnalysis) { delete fTriggerAnalysis; fTriggerAnalysis=0; } @@ -272,9 +275,22 @@ void AliAnalysisTaskMultiDielectron::UserExec(Option_t *) //Process event in all AliDielectron instances // TIter nextDie(&fListDielectron); // AliDielectron *die=0; + Bool_t sel=kFALSE; Int_t idie=0; while ( (die=static_cast(nextDie())) ){ - die->Process(InputEvent()); + if(die->DoEventProcess()) { + sel= die->Process(InputEvent()); + // input for internal train + if(die->DontClearArrays()) { + fPairArray = (*(die->GetPairArraysPointer())); + + } + } + else { + // internal train + if(sel) die->Process(fPairArray); + } + if (die->HasCandidates()){ Int_t ncandidates=die->GetPairArray(1)->GetEntriesFast(); if (ncandidates==1) fEventStat->Fill((kNbinsEvent)+2*idie); @@ -282,7 +298,7 @@ void AliAnalysisTaskMultiDielectron::UserExec(Option_t *) } ++idie; } - + PostData(1, &fListHistos); PostData(2, &fListCF); PostData(3,fEventStat); @@ -295,13 +311,46 @@ void AliAnalysisTaskMultiDielectron::FinishTaskOutput() // Write debug tree // TIter nextDie(&fListDielectron); + Int_t ic=0; AliDielectron *die=0; + AliDielectron *die2=0; + + // main loop while ( (die=static_cast(nextDie())) ){ + ic++; + + // debug tree die->SaveDebugTree(); + + // skip internal train tasks in main loop + if(!die->DoEventProcess()) continue; + + // mix remaining AliDielectronMixingHandler *mix=die->GetMixingHandler(); -// printf("\n\n\n===============\ncall mix in Terminate: %p (%p)\n=================\n\n",mix,die); - if (mix) mix->MixRemaining(die); + if (!mix || !mix->GetMixUncomplete()) continue; + + // loop over all pools + for (Int_t ipool=0; ipoolGetNumberOfBins(); ++ipool){ + // printf("mix remaining %04d/%04d \n",ipool,mix->GetNumberOfBins()); + mix->MixRemaining(die, ipool); + fPairArray = (*(die->GetPairArraysPointer())); + if(!fPairArray) continue; + + // loop over internal train task candidates + for(Int_t i=ic; i(fListDielectron.At(i)); + if(die2->DoEventProcess()) continue; + // fill internal train output + die2->SetPairArraysPointer(fPairArray); + // printf(" --> fill internal train output %s \n",die2->GetName()); + die2->FillHistogramsFromPairArray(kTRUE); + } + // printf("\n\n\n===============\ncall mix in Terminate: %p (%p)\n=================\n\n",mix,die); + + } + } + PostData(1, &fListHistos); PostData(2, &fListCF); } diff --git a/PWGDQ/dielectron/AliAnalysisTaskMultiDielectron.h b/PWGDQ/dielectron/AliAnalysisTaskMultiDielectron.h index 1f913f9afdf..94d47d050b6 100644 --- a/PWGDQ/dielectron/AliAnalysisTaskMultiDielectron.h +++ b/PWGDQ/dielectron/AliAnalysisTaskMultiDielectron.h @@ -58,6 +58,7 @@ public: protected: enum {kAllEvents=0, kSelectedEvents, kV0andEvents, kFilteredEvents, kPileupEvents, kNbinsEvent}; + TObjArray *fPairArray; //! output array TList fListDielectron; // List of dielectron framework instances TList fListHistos; //! List of histogram manager lists in the framework classes TList fListCF; //! List with CF Managers @@ -82,6 +83,6 @@ protected: AliAnalysisTaskMultiDielectron(const AliAnalysisTaskMultiDielectron &c); AliAnalysisTaskMultiDielectron& operator= (const AliAnalysisTaskMultiDielectron &c); - ClassDef(AliAnalysisTaskMultiDielectron, 3); //Analysis Task handling multiple instances of AliDielectron + ClassDef(AliAnalysisTaskMultiDielectron, 4); //Analysis Task handling multiple instances of AliDielectron }; #endif diff --git a/PWGDQ/dielectron/AliAnalysisTaskMultiDielectronTG.cxx b/PWGDQ/dielectron/AliAnalysisTaskMultiDielectronTG.cxx index f72970043d5..2ab96b032f8 100644 --- a/PWGDQ/dielectron/AliAnalysisTaskMultiDielectronTG.cxx +++ b/PWGDQ/dielectron/AliAnalysisTaskMultiDielectronTG.cxx @@ -622,7 +622,10 @@ void AliAnalysisTaskMultiDielectronTG::FinishTaskOutput() die->SaveDebugTree(); AliDielectronMixingHandler *mix=die->GetMixingHandler(); // printf("\n\n\n===============\ncall mix in Terminate: %p (%p)\n=================\n\n",mix,die); - if (mix) mix->MixRemaining(die); + if(!mix) continue; + for (Int_t ipool=0; ipoolGetNumberOfBins(); ++ipool){ + mix->MixRemaining(die, ipool); + } } PostData(1, &fListHistos); PostData(2, &fListCF); diff --git a/PWGDQ/dielectron/AliDielectron.cxx b/PWGDQ/dielectron/AliDielectron.cxx index a0f56769388..281d9ddb36f 100644 --- a/PWGDQ/dielectron/AliDielectron.cxx +++ b/PWGDQ/dielectron/AliDielectron.cxx @@ -66,6 +66,7 @@ The names are available via the function PairClassName(Int_t i) #include "AliDielectronDebugTree.h" #include "AliDielectronSignalMC.h" #include "AliDielectronMixingHandler.h" +#include "AliDielectronPairLegCuts.h" #include "AliDielectronV0Cuts.h" #include "AliDielectronPID.h" @@ -132,6 +133,7 @@ AliDielectron::AliDielectron() : fHasMC(kFALSE), fStoreRotatedPairs(kFALSE), fDontClearArrays(kFALSE), + fEventProcess(kTRUE), fEstimatorFilename(""), fTRDpidCorrectionFilename(""), fVZEROCalibrationFilename(""), @@ -183,6 +185,7 @@ AliDielectron::AliDielectron(const char* name, const char* title) : fHasMC(kFALSE), fStoreRotatedPairs(kFALSE), fDontClearArrays(kFALSE), + fEventProcess(kTRUE), fEstimatorFilename(""), fTRDpidCorrectionFilename(""), fVZEROCalibrationFilename(""), @@ -208,7 +211,7 @@ AliDielectron::~AliDielectron() if (fPairEffMap) delete fPairEffMap; if (fHistos) delete fHistos; if (fUsedVars) delete fUsedVars; - if (fPairCandidates) delete fPairCandidates; + if (fPairCandidates && fEventProcess) delete fPairCandidates; if (fDebugTree) delete fDebugTree; if (fMixing) delete fMixing; if (fSignalsMC) delete fSignalsMC; @@ -256,6 +259,18 @@ void AliDielectron::Init() if(fPostPIDCntrdCorr) AliDielectronPID::SetCentroidCorrFunction(fPostPIDCntrdCorr); if(fPostPIDWdthCorr) AliDielectronPID::SetWidthCorrFunction(fPostPIDWdthCorr); + if(!fEventProcess) { + AliDielectronPairLegCuts *trk2leg = new AliDielectronPairLegCuts("trk2leg","trk2leg"); + // move all track cuts (if any) into pair leg cuts + TIter listIterator(fTrackFilter.GetCuts()); + while (AliAnalysisCuts *thisCut = (AliAnalysisCuts*) listIterator()) { + trk2leg->GetLeg1Filter().AddCuts((AliAnalysisCuts*)thisCut->Clone()); + trk2leg->GetLeg2Filter().AddCuts((AliAnalysisCuts*)thisCut->Clone()); + } + // add pair leg cuts to pair filter + fPairFilter.AddCuts(trk2leg); + } + if (fCutQA) { fQAmonitor = new AliDielectronCutQA(Form("QAcuts_%s",GetName()),"QAcuts"); fQAmonitor->AddTrackFilter(&fTrackFilter); @@ -271,7 +286,31 @@ void AliDielectron::Init() } //________________________________________________________________ -void AliDielectron::Process(AliVEvent *ev1, AliVEvent *ev2) + +void AliDielectron::Process(TObjArray *arr) +{ + // + // Process the pair array + // + + // set pair arrays + fPairCandidates = arr; + + //fill debug tree if a manager is attached + // if (fDebugTree) FillDebugTree(); + //in case there is a histogram manager, fill the QA histograms + // if (fHistos && fSignalsMC) FillMCHistograms(ev1); + + // apply cuts and fill output + if (fHistos) FillHistogramsFromPairArray(); + + // never clear arrays !!!! + + +} + +//________________________________________________________________ +Bool_t AliDielectron::Process(AliVEvent *ev1, AliVEvent *ev2) { // // Process the events @@ -280,7 +319,7 @@ void AliDielectron::Process(AliVEvent *ev1, AliVEvent *ev2) //at least first event is needed! if (!ev1){ AliError("At least first event must be set!"); - return; + return 0; } // modify event numbers in MC so that we can identify new events @@ -320,7 +359,7 @@ void AliDielectron::Process(AliVEvent *ev1, AliVEvent *ev2) if(fCutQA) fQAmonitor->FillAll(ev1); if(fCutQA) fQAmonitor->Fill(cutmask,ev1); if ((ev1&&cutmask!=selectedMask) || - (ev2&&fEventFilter.IsSelected(ev2)!=selectedMask)) return; + (ev2&&fEventFilter.IsSelected(ev2)!=selectedMask)) return 0; //fill track arrays for the first event if (ev1){ @@ -387,6 +426,8 @@ void AliDielectron::Process(AliVEvent *ev1, AliVEvent *ev2) } } + return 1; + } //________________________________________________________________ @@ -1441,3 +1482,84 @@ THnBase* AliDielectron::InitEffMap(TString filename) printf("[I] AliDielectron::InitEffMap efficiency maps %s with %d dimensions loaded! \n",filename.Data(),hFnd->GetNdimensions()); return ((THnBase*) hFnd->Clone("effMap")); } + +//________________________________________________________________ +void AliDielectron::FillHistogramsFromPairArray(Bool_t pairInfoOnly/*=kFALSE*/) +{ + // + // Fill Histogram information for tracks and pairs + // + + TString className,className2; + Double_t values[AliDielectronVarManager::kNMaxValues]={0.}; + + //Fill event information + if(!pairInfoOnly) { + if(fHistos->GetHistogramList()->FindObject("Event")) { + fHistos->FillClass("Event", AliDielectronVarManager::kNMaxValues, AliDielectronVarManager::GetData()); + } + } + + UInt_t selectedMask=(1<GetEntries())-1; + + //Fill Pair information, separately for all pair candidate arrays and the legs + TObjArray arrLegs(100); + for (Int_t i=0; i<10; ++i){ // ROT pairs?? + Int_t npairs=PairArray(i)->GetEntriesFast(); + if(npairs<1) continue; + + className.Form("Pair_%s",fgkPairClassNames[i]); + className2.Form("Track_Legs_%s",fgkPairClassNames[i]); + Bool_t pairClass=fHistos->GetHistogramList()->FindObject(className.Data())!=0x0; + Bool_t legClass=fHistos->GetHistogramList()->FindObject(className2.Data())!=0x0; + + // if (!pairClass&&!legClass) continue; + for (Int_t ipair=0; ipair(PairArray(i)->UncheckedAt(ipair)); + + // apply cuts + UInt_t cutMask=fPairFilter.IsSelected(pair); + + // cut qa + if(i==kEv1PM && fCutQA) { + fQAmonitor->FillAll(pair); + fQAmonitor->Fill(cutMask,pair); + } + + //CF manager for the pair (TODO: check steps and if they are properly filled) + // if (fCfManagerPair) fCfManagerPair->Fill(cutMask,pair); + + //apply cut + if (cutMask!=selectedMask) continue; + + //histogram array for the pair + if (fHistoArray) fHistoArray->Fill(i,pair); + + AliDielectronVarManager::SetFillMap(fUsedVars); + //fill pair information + if (pairClass){ + AliDielectronVarManager::Fill(pair, values); + fHistos->FillClass(className, AliDielectronVarManager::kNMaxValues, values); + } + + //fill leg information, don't fill the information twice + if (legClass){ + AliVParticle *d1=pair->GetFirstDaughter(); + AliVParticle *d2=pair->GetSecondDaughter(); + if (!arrLegs.FindObject(d1)){ + AliDielectronVarManager::Fill(d1, values); + fHistos->FillClass(className2, AliDielectronVarManager::kNMaxValues, values); + arrLegs.Add(d1); + } + if (!arrLegs.FindObject(d2)){ + AliDielectronVarManager::Fill(d2, values); + fHistos->FillClass(className2, AliDielectronVarManager::kNMaxValues, values); + arrLegs.Add(d2); + } + } + } + if (legClass) arrLegs.Clear(); + } + +} + diff --git a/PWGDQ/dielectron/AliDielectron.h b/PWGDQ/dielectron/AliDielectron.h index fe24b6eb6f7..933c22edf46 100644 --- a/PWGDQ/dielectron/AliDielectron.h +++ b/PWGDQ/dielectron/AliDielectron.h @@ -55,8 +55,9 @@ public: virtual ~AliDielectron(); void Init(); - - void Process(AliVEvent *ev1, AliVEvent *ev2=0); + + void Process(/*AliVEvent *ev1, */TObjArray *arr); + Bool_t Process(AliVEvent *ev1, AliVEvent *ev2=0); const AliAnalysisFilter& GetEventFilter() const { return fEventFilter; } const AliAnalysisFilter& GetTrackFilter() const { return fTrackFilter; } @@ -85,6 +86,7 @@ public: static_cast(fPairCandidates->UncheckedAt(i)):0;} TObjArray** GetPairArraysPointer() { return &fPairCandidates; } + void SetPairArraysPointer( TObjArray *arr) { fPairCandidates=arr; } void SetHistogramArray(AliDielectronHF * const histoarray) { fHistoArray=histoarray; } const TObjArray * GetHistogramArray() const { return fHistoArray?fHistoArray->GetHistArray():0x0; } const TObjArray * GetQAHistArray() const { return fQAmonitor?fQAmonitor->GetQAHistArray():0x0; } @@ -118,6 +120,7 @@ public: void SetStoreRotatedPairs(Bool_t storeTR) {fStoreRotatedPairs = storeTR;} void SetDontClearArrays(Bool_t dontClearArrays=kTRUE) { fDontClearArrays=dontClearArrays; } + Bool_t DontClearArrays() const { return fDontClearArrays; } void AddSignalMC(AliDielectronSignalMC* signal); @@ -139,6 +142,9 @@ public: void SetWidthCorrFunction(TF1 *fun, UInt_t varx, UInt_t vary=0, UInt_t varz=0); void SaveDebugTree(); + Bool_t DoEventProcess() const { return fEventProcess; } + void SetEventProcess(Bool_t setValue=kTRUE) { fEventProcess=setValue; } + void FillHistogramsFromPairArray(Bool_t pairInfoOnly=kFALSE); private: @@ -193,7 +199,8 @@ private: Bool_t fHasMC; //If we run with MC, at the moment only needed in AOD Bool_t fStoreRotatedPairs; //It the rotated pairs should be stored in the pair array Bool_t fDontClearArrays; //Don't clear the arrays at the end of the Process function, needed for external use of pair and tracks - + Bool_t fEventProcess; //Process event (or pair array) + void FillTrackArrays(AliVEvent * const ev, Int_t eventNr=0); void EventPlanePreFilter(Int_t arr1, Int_t arr2, TObjArray arrTracks1, TObjArray arrTracks2, const AliVEvent *ev); void PairPreFilter(Int_t arr1, Int_t arr2, TObjArray &arrTracks1, TObjArray &arrTracks2); diff --git a/PWGDQ/dielectron/AliDielectronMixingHandler.cxx b/PWGDQ/dielectron/AliDielectronMixingHandler.cxx index 67f7c4f2f1f..3efbd51fd75 100644 --- a/PWGDQ/dielectron/AliDielectronMixingHandler.cxx +++ b/PWGDQ/dielectron/AliDielectronMixingHandler.cxx @@ -161,6 +161,16 @@ void AliDielectronMixingHandler::Fill(const AliVEvent *ev, AliDielectron *diele) } TClonesArray &pool=*poolp; + // clear the current pool if its size was reached by last event + // clear before fill new event into it + // NOTE: clear not directly after DoMixing, because you may want to use the ME + // in the internal train by other configs/tasks + // reset the event pool size to 1 (this keeps the physical memory consumption low) + if(pool.GetEntriesFast()==fDepth) { + pool.Clear("C"); + pool.ExpandCreate(1); + } + AliDebug(10,Form("new event at %d: %d",bin,pool.GetEntriesFast())); AliDielectronEvent *event=new(pool[pool.GetEntriesFast()]) AliDielectronEvent(); if(ev->IsA() == AliAODEvent::Class()) event->SetAOD(TMath::Max(diele->GetTrackArray(0)->GetEntriesFast(),diele->GetTrackArray(1)->GetEntriesFast())); @@ -181,10 +191,7 @@ void AliDielectronMixingHandler::Fill(const AliVEvent *ev, AliDielectron *diele) diele->fHistos->Fill("Mixing","Stats",0); diele->fHistos->Fill("Mixing","CompletePools",bin); } - - //clear the current pool and release memory - pool.Clear("C"); - pool.ExpandCreate(1); + } //______________________________________________ @@ -305,7 +312,7 @@ void AliDielectronMixingHandler::DoMixing(TClonesArray &pool, AliDielectron *die } //______________________________________________ -void AliDielectronMixingHandler::MixRemaining(AliDielectron *diele) +void AliDielectronMixingHandler::MixRemaining(AliDielectron *diele, Int_t ipool) { // // mix all pools even if they are incomplete @@ -315,9 +322,8 @@ void AliDielectronMixingHandler::MixRemaining(AliDielectron *diele) if (!diele || !diele->PairArray(0) || !fMixIncomplete ) return; AliDielectronVarManager::SetEvent(0x0); - for (Int_t ipool=0; ipool(fArrPools.At(ipool)); - if (!poolp || !poolp->GetEntriesFast() || !poolp->At(0)) continue; + if (!poolp || !poolp->GetEntriesFast() || !poolp->At(0)) return; //clear the arrays before the final processing" AliDebug(10,Form("Incomplete: Bin %d (%d)\n",ipool,poolp->GetEntriesFast())); diele->ClearArrays(); @@ -344,7 +350,6 @@ void AliDielectronMixingHandler::MixRemaining(AliDielectron *diele) AliDielectronVarManager::SetEventData(values); } - } } diff --git a/PWGDQ/dielectron/AliDielectronMixingHandler.h b/PWGDQ/dielectron/AliDielectronMixingHandler.h index 477a996c688..79d097962b5 100644 --- a/PWGDQ/dielectron/AliDielectronMixingHandler.h +++ b/PWGDQ/dielectron/AliDielectronMixingHandler.h @@ -58,7 +58,7 @@ public: Int_t FindBin(const Double_t values[], TString *dim=0x0); void Fill(const AliVEvent *ev, AliDielectron *diele); - void MixRemaining(AliDielectron *diele); + void MixRemaining(AliDielectron *diele, Int_t ipool); void Init(const AliDielectron *diele=0x0); static void MoveToSameVertex(AliVTrack * const vtrack, const Double_t vFirst[3], const Double_t vMix[3]); diff --git a/PWGDQ/dielectron/AliDielectronPairLegCuts.cxx b/PWGDQ/dielectron/AliDielectronPairLegCuts.cxx index 0c62499ca57..3c4bb1b3989 100644 --- a/PWGDQ/dielectron/AliDielectronPairLegCuts.cxx +++ b/PWGDQ/dielectron/AliDielectronPairLegCuts.cxx @@ -81,6 +81,10 @@ Bool_t AliDielectronPairLegCuts::IsSelected(TObject* track) //test cuts Bool_t isLeg1selected=(fFilterLeg1.IsSelected(leg1)==selectedMaskLeg1); + if(fCutType==kBothLegs && !isLeg1selected) { + SetSelected(isLeg1selected); + return isLeg1selected; + } Bool_t isLeg2selected=(fFilterLeg2.IsSelected(leg2)==selectedMaskLeg2); Bool_t isLeg1selectedMirror=(fFilterLeg1.IsSelected(leg2)==selectedMaskLeg1); -- 2.43.0