1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 * appear 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 **************************************************************************/
17 // Helper Class that contains a lot of
18 // usefull static functions jet matchin pythia access etc.
20 // Author: C. Klein-Boesing IKP Muenster
23 #include "TDirectory.h"
29 #include "THnSparse.h"
30 #include "TSeqCollection.h"
31 #include "TMethodCall.h"
38 #include "AliMCEvent.h"
40 #include "AliESDEvent.h"
41 #include "AliAODJet.h"
42 #include "AliAODEvent.h"
44 #include "AliGenEventHeader.h"
45 #include "AliGenCocktailEventHeader.h"
46 #include <AliGenDPMjetEventHeader.h>
47 #include "AliGenPythiaEventHeader.h"
50 #include "AliAnalysisHelperJetTasks.h"
51 #include "TMatrixDSym.h"
52 #include "TMatrixDSymEigen.h"
56 ClassImp(AliAnalysisHelperJetTasks)
58 Int_t AliAnalysisHelperJetTasks::fgLastProcessType = -1;
61 AliGenPythiaEventHeader* AliAnalysisHelperJetTasks::GetPythiaEventHeader(const AliMCEvent *mcEvent){
63 // Fetch the pythia event header
66 AliGenEventHeader* genHeader = mcEvent->GenEventHeader();
67 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(genHeader);
70 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(genHeader);
72 if (!genCocktailHeader) {
73 AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Unknown header type (not Pythia or Cocktail)");
74 // AliWarning(Form("%s %d: Unknown header type (not Pythia or Cocktail)",(char*)__FILE__,__LINE__));
77 TList* headerList = genCocktailHeader->GetHeaders();
78 for (Int_t i=0; i<headerList->GetEntries(); i++) {
79 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
84 AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Pythia event header not found");
88 return pythiaGenHeader;
93 void AliAnalysisHelperJetTasks::PrintStack(AliMCEvent *mcEvent,Int_t iFirst,Int_t iLast,Int_t iMaxPrint){
95 // Print the stack informatuin up to the iMaxPrint event
98 AliStack *stack = mcEvent->Stack();
100 Printf("%s%d No Stack available",(char*)__FILE__,__LINE__);
104 static Int_t iCount = 0;
105 if(iCount>iMaxPrint)return;
106 Int_t nStack = stack->GetNtrack();
107 if(iLast == 0)iLast = nStack;
108 else if(iLast > nStack)iLast = nStack;
111 Printf("####################################################################");
112 for(Int_t np = iFirst;np<iLast;++np){
113 TParticle *p = stack->Particle(np);
114 Printf("Nr.%d --- Status %d ---- Mother1 %d Mother2 %d Daughter1 %d Daughter2 %d ",
115 np,p->GetStatusCode(),p->GetMother(0),p->GetMother(1),p->GetDaughter(0),p->GetDaughter(1));
116 Printf("Eta %3.3f Phi %3.3f ",p->Eta(),p->Phi());
118 Printf("---------------------------------------");
126 void AliAnalysisHelperJetTasks::GetClosestJets(const AliAODJet *genJets,const Int_t &kGenJets,
127 const AliAODJet *recJets,const Int_t &kRecJets,
128 Int_t *iGenIndex,Int_t *iRecIndex,
129 Int_t iDebug,Float_t maxDist){
132 // Relate the two input jet Arrays
136 // The association has to be unique
137 // So check in two directions
138 // find the closest rec to a gen
139 // and check if there is no other rec which is closer
140 // Caveat: Close low energy/split jets may disturb this correlation
143 // Idea: search in two directions generated e.g (a--e) and rec (1--3)
144 // Fill a matrix with Flags (1 for closest rec jet, 2 for closest rec jet
145 // in the end we have something like this
159 // Only entries with "3" match from both sides
161 // In case we have more jets than kmaxjets only the
162 // first kmaxjets are searched
164 // use kMaxJets for a test not to fragemnt the memory...
166 for(int i = 0;i < kRecJets;++i)iGenIndex[i] = -1;
167 for(int j = 0;j < kGenJets;++j)iRecIndex[j] = -1;
173 const Int_t nGenJets = TMath::Min(kMaxJets,kGenJets);
174 const Int_t nRecJets = TMath::Min(kMaxJets,kRecJets);
176 if(nRecJets==0||nGenJets==0)return;
178 // UShort_t *iFlag = new UShort_t[nGenJets*nRecJets];
179 UShort_t iFlag[kMaxJets*kMaxJets] = {0}; // all values set to zero
180 for(int i = 0;i < nGenJets;++i){
181 for(int j = 0;j < nRecJets;++j){
182 iFlag[i*nGenJets+j] = 0;
188 // find the closest distance to the generated
189 for(int ig = 0;ig<nGenJets;++ig){
190 Float_t dist = maxDist;
191 if(iDebug>1)Printf("Gen (%d) p_T %3.3f eta %3.3f ph %3.3f ",ig,genJets[ig].Pt(),genJets[ig].Eta(),genJets[ig].Phi());
192 for(int ir = 0;ir<nRecJets;++ir){
194 printf("Rec (%d) ",ir);
195 Printf("p_T %3.3f eta %3.3f ph %3.3f ",recJets[ir].Pt(),recJets[ir].Eta(),recJets[ir].Phi());
197 Double_t dR = genJets[ig].DeltaR(&recJets[ir]);
198 if(iDebug>1)Printf("Distance (%d)--(%d) %3.3f ",ig,ir,dR);
204 if(iRecIndex[ig]>=0)iFlag[ig*nRecJets+iRecIndex[ig]]+=1;
209 for(int ir = 0;ir<nRecJets;++ir){
210 Float_t dist = maxDist;
211 for(int ig = 0;ig<nGenJets;++ig){
212 Double_t dR = genJets[ig].DeltaR(&recJets[ir]);
218 if(iGenIndex[ir]>=0)iFlag[iGenIndex[ir]*nRecJets+ir]+=2;
223 // check for "true" correlations
225 if(iDebug>1)Printf(">>>>>> Matrix");
227 for(int ig = 0;ig<nGenJets;++ig){
228 for(int ir = 0;ir<nRecJets;++ir){
230 if(iDebug>1)printf("Flag[%d][%d] %d ",ig,ir,iFlag[ig*nRecJets+ir]);
233 // we have a uniqie correlation
234 if(iFlag[ig*nRecJets+ir]==3){
240 // we just take the correlation from on side
241 if((iFlag[ig*nRecJets+ir]&2)==2){
244 if((iFlag[ig*nRecJets+ir]&1)==1){
249 if(iDebug>1)printf("\n");
255 void AliAnalysisHelperJetTasks::GetClosestJets(const TList *genJetsList,const Int_t &kGenJets,
256 const TList *recJetsList,const Int_t &kRecJets,
257 TArrayI &iGenIndex,TArrayI &iRecIndex,
258 Int_t iDebug,Float_t maxDist){
260 // Size indepnedendentt Implemenation of jet matching
261 // Thepassed TArrayI should be static in the user function an only increased if needed
264 // Relate the two input jet Arrays
268 // The association has to be unique
269 // So check in two directions
270 // find the closest rec to a gen
271 // and check if there is no other rec which is closer
272 // Caveat: Close low energy/split jets may disturb this correlation
275 // Idea: search in two directions generated e.g (a--e) and rec (1--3)
276 // Fill a matrix with Flags (1 for closest rec jet, 2 for closest rec jet
277 // in the end we have something like this
291 // Only entries with "3" match from both sides
297 const Int_t nGenJets = TMath::Min(genJetsList->GetEntries(),kGenJets);
298 const Int_t nRecJets = TMath::Min(recJetsList->GetEntries(),kRecJets);
299 if(nRecJets==0||nGenJets==0)return;
301 static TArrayS iFlag(nGenJets*nRecJets);
302 if(iFlag.GetSize()<(nGenJets*nRecJets)){
303 iFlag.Set(nGenJets*nRecJets);
307 // find the closest distance to the generated
308 for(int ig = 0;ig<nGenJets;++ig){
309 AliAODJet *genJet = (AliAODJet*)genJetsList->At(ig);
312 Float_t dist = maxDist;
313 if(iDebug>1)Printf("Gen (%d) p_T %3.3f eta %3.3f ph %3.3f ",ig,genJet->Pt(),genJet->Eta(),genJet->Phi());
314 for(int ir = 0;ir<nRecJets;++ir){
315 AliAODJet *recJet = (AliAODJet*)recJetsList->At(ir);
318 printf("Rec (%d) ",ir);
319 Printf("p_T %3.3f eta %3.3f ph %3.3f ",recJet->Pt(),recJet->Eta(),recJet->Phi());
321 Double_t dR = genJet->DeltaR(recJet);
322 if(iDebug>1)Printf("Distance (%d)--(%d) %3.3f ",ig,ir,dR);
328 if(iRecIndex[ig]>=0)iFlag[ig*nRecJets+iRecIndex[ig]]+=1;
334 for(int ir = 0;ir<nRecJets;++ir){
335 AliAODJet *recJet = (AliAODJet*)recJetsList->At(ir);
337 Float_t dist = maxDist;
338 for(int ig = 0;ig<nGenJets;++ig){
339 AliAODJet *genJet = (AliAODJet*)genJetsList->At(ig);
341 Double_t dR = genJet->DeltaR(recJet);
347 if(iGenIndex[ir]>=0)iFlag[iGenIndex[ir]*nRecJets+ir]+=2;
352 // check for "true" correlations
354 if(iDebug>1)Printf(">>>>>> Matrix Size %d",iFlag.GetSize());
356 for(int ig = 0;ig<nGenJets;++ig){
357 for(int ir = 0;ir<nRecJets;++ir){
359 if(iDebug>1)printf("Flag2[%d][%d] %d ",ig,ir,iFlag[ig*nRecJets+ir]);
362 // we have a uniqie correlation
363 if(iFlag[ig*nRecJets+ir]==3){
369 // we just take the correlation from on side
370 if((iFlag[ig*nRecJets+ir]&2)==2){
373 if((iFlag[ig*nRecJets+ir]&1)==1){
378 if(iDebug>1)printf("\n");
382 void AliAnalysisHelperJetTasks::GetJetMatching(const TList *genJetsList, const Int_t &kGenJets,
383 const TList *recJetsList, const Int_t &kRecJets,
384 TArrayI &iMatchIndex, TArrayF &fPtFraction,
385 Int_t iDebug, Float_t maxDist, Int_t mode){
388 // Matching jets from two lists
389 // Start with highest energetic jet from first list (generated/embedded)
390 // Calculate distance (\Delta R) to all jets from second list (reconstructed)
391 // Select N closest jets = kClosestJetsN
392 // Check energy fraction from jets from first list in jets from second list
393 // Matched jets = jet with largest energy fraction
394 // Store index of matched jet in TArrayI iMatchIndex
397 iMatchIndex.Reset(-1);
398 fPtFraction.Reset(-1.);
400 // N closest jets: store list with index and \Delta R
401 const Int_t kClosestJetsN = 4;
402 Double_t closestJets[kClosestJetsN][2]; //[][0] = index, [][1] = \Delta R
404 const Int_t nGenJets = TMath::Min(genJetsList->GetEntries(),kGenJets);
405 const Int_t nRecJets = TMath::Min(recJetsList->GetEntries(),kRecJets);
406 if(nRecJets==0||nGenJets==0) return;
408 AliAODJet *genJet = 0x0;
409 AliAODJet *recJet = 0x0;
411 // loop over generated/embedded jets
412 for(Int_t ig=0; ig<nGenJets; ++ig){
414 for(Int_t i=0; i<kClosestJetsN; ++i){
415 closestJets[i][0] = -1; // index
416 closestJets[i][1] = 1e6; // delta R
419 genJet = (AliAODJet*)genJetsList->At(ig);
420 //if(!genJet || !JetSelected(genJet)) continue;
421 if(!genJet) continue;
423 // find N closest reconstructed jets
424 Double_t deltaR = 0.;
425 for(Int_t ir=0; ir<nRecJets; ++ir){
426 recJet = (AliAODJet*)recJetsList->At(ir);
427 //if(!recJet || !JetSelected(recJet)) continue;
428 if(!recJet) continue;
430 deltaR = genJet->DeltaR(recJet);
432 Int_t i=kClosestJetsN-1;
433 if(deltaR<closestJets[i][1] && deltaR<maxDist){
434 closestJets[i][0] = (Double_t) ir; // index
435 closestJets[i][1] = deltaR;
437 // sort array (closest at the beginning)
438 while(i>=1 && closestJets[i][1]<closestJets[i-1][1]){
440 for(Int_t j=0; j<2; j++){
441 tmpArr[j] = closestJets[i-1][j];
442 closestJets[i-1][j] = closestJets[i][j];
443 closestJets[i][j] = tmpArr[j];
448 } // end: loop over reconstructed jets
450 // calculate fraction for the N closest jets
451 Double_t maxFraction = -1.; // maximum found fraction in one jets
452 Double_t cumFraction = 0.; // cummulated fraction of closest jets (for break condition)
453 Double_t fraction = 0.;
454 Int_t ir = -1; // index of close reconstruced jet
456 for(Int_t irc=0; irc<kClosestJetsN; irc++){
457 ir = (Int_t)(closestJets[irc][0]);
458 if(ir<0 || ir>nRecJets-1) continue;
459 recJet = (AliAODJet*)recJetsList->At(ir);
460 if(!(recJet)) continue;
462 fraction = GetFractionOfJet(recJet,genJet,mode);
464 cumFraction += fraction;
466 // check if jet fullfills current matching condition
467 if(fraction>maxFraction){
468 // avoid multiple links
469 for(Int_t ij=0; ij<ig; ++ij){
470 if(iMatchIndex[ij]==ir) continue;
473 maxFraction = fraction;
474 fPtFraction[ig] = fraction;
475 iMatchIndex[ig] = ir;
477 // break condition: less energy left as already found in one jet or
478 // as required for positiv matching
479 if(1-cumFraction<maxFraction) break;
480 } // end: loop over closest jets
482 if(iMatchIndex[ig]<0){
483 if(iDebug) Printf("Matching failed for (gen) jet #%d", ig);
488 Double_t AliAnalysisHelperJetTasks::GetFractionOfJet(const AliAODJet *recJet, const AliAODJet *genJet, Int_t mode){
490 // get the fraction of hte signal jet in the full jt
492 Double_t ptGen = genJet->Pt();
493 if(ptGen==0.) return 999.;
495 Double_t ptAssocTracks = 0.; // sum of pT of tracks found in both jets
497 // look at tracks inside jet
498 TRefArray *genTrackList = genJet->GetRefTracks();
499 TRefArray *recTrackList = recJet->GetRefTracks();
500 Int_t nTracksGenJet = genTrackList->GetEntriesFast();
501 Int_t nTracksRecJet = recTrackList->GetEntriesFast();
503 AliAODTrack* recTrack;
504 AliAODTrack* genTrack;
505 for(Int_t ir=0; ir<nTracksRecJet; ++ir){
506 recTrack = (AliAODTrack*)(recTrackList->At(ir));
507 if(!recTrack) continue;
509 for(Int_t ig=0; ig<nTracksGenJet; ++ig){
510 genTrack = (AliAODTrack*)(genTrackList->At(ig));
511 if(!genTrack) continue;
513 // look if it points to the same track
514 if( (mode&1)!=0 && genTrack==recTrack){
515 ptAssocTracks += genTrack->Pt();
520 && genTrack->GetLabel()>-1
521 && recTrack->GetLabel()>-1
522 && genTrack->GetLabel()==recTrack->GetLabel()){
524 ptAssocTracks += genTrack->Pt();
530 // calculate fraction
531 Double_t fraction = ptAssocTracks/ptGen;
537 void AliAnalysisHelperJetTasks::MergeOutputDirs(const char* cFiles,const char* cPattern,const char *cOutFile,Bool_t bUpdate){
538 // Routine to merge only directories containing the pattern
540 TString outFile(cOutFile);
541 if(outFile.Length()==0)outFile = Form("%s.root",cPattern);
547 while(in1>>cFile){// only open the first file
548 Printf("Adding %s",cFile);
549 TFile *f1 = TFile::Open(cFile);
554 if(fileList.GetEntries()){// open the first file
555 TFile* fIn = dynamic_cast<TFile*>(fileList.At(0));
557 Printf("Input File not Found");
560 // fetch the keys for the directories
561 TList *ldKeys = fIn->GetListOfKeys();
562 for(int id = 0;id < ldKeys->GetEntries();id++){
563 // check if it is a directory
564 TKey *dKey = (TKey*)ldKeys->At(id);
565 TDirectory *dir = dynamic_cast<TDirectory*>(dKey->ReadObj());
567 TString dName(dir->GetName());
568 if(dName.Contains(cPattern)){
569 // open new file if first match
571 if(bUpdate)fOut = new TFile(outFile.Data(),"UPDATE");
572 else fOut = new TFile(outFile.Data(),"RECREATE");
574 // merge all the stuff that is in this directory
575 TList *llKeys = dir->GetListOfKeys();
580 TDirectory *dOut = fOut->mkdir(dir->GetName());
582 for(int il = 0;il < llKeys->GetEntries();il++){
583 TKey *lKey = (TKey*)llKeys->At(il);
584 TObject *object = dynamic_cast<TObject*>(lKey->ReadObj());
585 // from TSeqCollections::Merge
587 // If current object is not mergeable just skip it
588 if (!object->IsA()) {
591 callEnv.InitWithPrototype(object->IsA(), "Merge", "TCollection*");
592 if (!callEnv.IsValid()) {
595 // Current object mergeable - get corresponding objects in input lists
596 tmplist = new TList();
597 for(int i = 1; i < fileList.GetEntries();i++){
598 TDirectory *fInTmp = dynamic_cast<TDirectory*>(fileList.At(i));
600 Printf("File %d not found",i);
603 TDirectory *dTmp = (TDirectory*)fInTmp->Get(dName.Data());
605 Printf("Directory %s not found",dName.Data());
608 TObject* oTmp = (TObject*)dTmp->Get(object->GetName());
610 Printf("Object %s not found",object->GetName());
615 callEnv.SetParam((Long_t) tmplist);
616 callEnv.Execute(object);
617 delete tmplist;tmplist = 0;
619 object->Write(object->GetName(),TObject::kSingleKey);
630 void AliAnalysisHelperJetTasks::MergeOutput(const char* cFiles,const char* cDir,const char *cList,const char *cOutFile,Bool_t bUpdate){
632 // This is used to merge the analysis-output from different
633 // data samples/pt_hard bins
634 // in case the eventweigth was set to xsection/ntrials already, this
635 // is not needed. Both methods only work in case we do not mix different
636 // pt_hard bins, and do not have overlapping bins
638 const Int_t nMaxBins = 12;
639 // LHC08q jetjet100: Mean = 1.42483e-03, RMS = 6.642e-05
640 // LHC08r jetjet50: Mean = 2.44068e-02, RMS = 1.144e-03
641 // LHC08v jetjet15-50: Mean = 2.168291 , RMS = 7.119e-02
642 // const Float_t xsection[nBins] = {2.168291,2.44068e-02};
644 Float_t xsection[nMaxBins];
645 Float_t nTrials[nMaxBins];
646 Float_t sf[nMaxBins];
647 TList *lIn[nMaxBins];
648 TDirectory *dIn[nMaxBins];
649 TFile *fIn[nMaxBins];
657 fIn[ibTotal] = TFile::Open(cFile);
659 dIn[ibTotal] = gDirectory;
662 dIn[ibTotal] = (TDirectory*)fIn[ibTotal]->Get(cDir);
665 Printf("%s:%d No directory %s found, exiting...",__FILE__,__LINE__,cDir);
670 lIn[ibTotal] = (TList*)dIn[ibTotal]->Get(cList);
671 Printf("Merging file %s %s",cFile, cDir);
673 Printf("%s:%d No list %s found, exiting...",__FILE__,__LINE__,cList);
677 TH1* hTrials = (TH1F*)lIn[ibTotal]->FindObject("fh1Trials");
679 Printf("%s:%d fh1PtHard_Trials not found in list, exiting...",__FILE__,__LINE__);
682 TProfile* hXsec = (TProfile*)lIn[ibTotal]->FindObject("fh1Xsec");
684 Printf("%s:%d fh1Xsec not found in list, exiting...",__FILE__,__LINE__);
687 xsection[ibTotal] = hXsec->GetBinContent(1);
688 nTrials[ibTotal] = hTrials->Integral();
689 sf[ibTotal] = xsection[ibTotal]/ nTrials[ibTotal];
694 Printf("%s:%d No files found for mergin, exiting",__FILE__,__LINE__);
699 if(bUpdate)fOut = new TFile(cOutFile,"UPDATE");
700 else fOut = new TFile(cOutFile,"RECREATE");
701 TDirectory *dOut = fOut->mkdir(dIn[0]->GetName());
703 TList *lOut = new TList();
704 lOut->SetName(lIn[0]->GetName());
706 // for the start scale all...
707 for(int ie = 0; ie < lIn[0]->GetEntries();++ie){
709 THnSparse *hnAdd = 0;
710 for(int ib = 0;ib < ibTotal;++ib){
711 // dynamic cast does not work with cint
712 TObject *h = lIn[ib]->At(ie);
713 if(h->InheritsFrom("TH1")){
716 h1Add = (TH1*)h1->Clone(h1->GetName());
717 h1Add->Scale(sf[ib]);
720 h1Add->Add(h1,sf[ib]);
723 else if(h->InheritsFrom("THnSparse")){
724 THnSparse *hn = (THnSparse*)h;
726 hnAdd = (THnSparse*)hn->Clone(hn->GetName());
727 hnAdd->Scale(sf[ib]);
730 hnAdd->Add(hn,sf[ib]);
736 if(h1Add)lOut->Add(h1Add);
737 else if(hnAdd)lOut->Add(hnAdd);
740 lOut->Write(lOut->GetName(),TObject::kSingleKey);
744 Bool_t AliAnalysisHelperJetTasks::PythiaInfoFromFile(const char* currFile,Float_t &fXsec,Float_t &fTrials){
746 // get the cross section and the trails either from pyxsec.root or from pysec_hists.root
747 // This is to called in Notify and should provide the path to the AOD/ESD file
749 TString file(currFile);
753 if(file.Contains("root_archive.zip#")){
754 Ssiz_t pos1 = file.Index("root_archive",12,0,TString::kExact);
755 Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
756 Ssiz_t pos2 = file.Index(".root",5,TString::kExact);
757 file.Replace(pos+1,pos2-pos1,"");
760 // not an archive take the basename....
761 file.ReplaceAll(gSystem->BaseName(file.Data()),"");
763 Printf("%s",file.Data());
768 TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root")); // problem that we cannot really test the existance of a file in a archive so we have to lvie with open error message from root
770 // next trial fetch the histgram file
771 fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
773 // not a severe condition but inciate that we have no information
777 // find the tlist we want to be independtent of the name so use the Tkey
778 TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0);
783 TList *list = dynamic_cast<TList*>(key->ReadObj());
788 fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
789 fTrials = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
792 } // no tree pyxsec.root
794 TTree *xtree = (TTree*)fxsec->Get("Xsection");
800 Double_t xsection = 0;
801 xtree->SetBranchAddress("xsection",&xsection);
802 xtree->SetBranchAddress("ntrials",&ntrials);
811 Bool_t AliAnalysisHelperJetTasks::PrintDirectorySize(const char* currFile,Int_t iDetail){
814 // Print the size on disk and in memory occuppied by a directory
818 if(iDetail>=0)fDummy = TFile::Open("/tmp/dummy.root","RECREATE");
820 TFile *fIn = TFile::Open(currFile);
822 // not a severe condition but inciate that we have no information
825 // find the tlists we want to be independtent of the name so use the Tkey
826 TList* keyList = fIn->GetListOfKeys();
827 Float_t memorySize = 0;
828 Float_t diskSize = 0;
830 for(int i = 0;i < keyList->GetEntries();i++){
831 TKey* ikey = (TKey*)keyList->At(i);
833 // TList *list = dynamic_cast<TList*>(key->ReadObj());
834 // TNamed *name = dynamic_cast<TNamed*>(ikey->ReadObj());
835 TDirectory *dir = dynamic_cast<TDirectory*>(ikey->ReadObj());
841 Printf("%03d : %60s %8d %8d ",i,dir->GetName(),ikey->GetObjlen(),ikey->GetNbytes());
842 TList * dirKeyList = dir->GetListOfKeys();
843 for(int j = 0;j<dirKeyList->GetEntries();j++){
844 TKey* jkey = (TKey*)dirKeyList->At(j);
845 TList *list = dynamic_cast<TList*>(jkey->ReadObj());
847 memorySize += (Float_t)jkey->GetObjlen()/1024./1024.;
848 diskSize += (Float_t)jkey->GetNbytes()/1024./1024.;
850 Printf("%03d/%03d: %60s %5.2f MB %5.2f MB",i,j,list->GetName(),(Float_t)jkey->GetObjlen()/1024./1024.,(Float_t)jkey->GetNbytes()/1024./1024.);
852 for(int il = 0;il<list->GetEntries();il++){
853 TObject *ob = list->At(il);
856 Int_t nBytesWrite = ob->Write();
857 Printf("%03d/%03d/%03d: %60s %5.2f kB",i,j,il,ob->GetName(),(Float_t)nBytesWrite/1024.);
863 Printf("%03d/%03d: %60s %5.2f MB %5.2f MB",i,j,jkey->GetName(),(Float_t)jkey->GetObjlen()/1024./1024.,(Float_t)jkey->GetNbytes()/1024./1024.);
868 Printf("Total %5.2f MB %5.2f MB",memorySize,diskSize);
873 Bool_t AliAnalysisHelperJetTasks::Selected(Bool_t bSet,Bool_t bNew){
875 // Static helper task, (re)set event by event
879 static Bool_t bSelected = kTRUE; // if service task is not run we acccpet all
886 Bool_t AliAnalysisHelperJetTasks::IsCosmic(){
887 return ((SelectInfo()&kIsCosmic)==kIsCosmic);
890 Bool_t AliAnalysisHelperJetTasks::IsPileUp(){
891 return ((SelectInfo()&kIsPileUp)==kIsPileUp);
895 Bool_t AliAnalysisHelperJetTasks::TestSelectInfo(UInt_t iMask){
896 return ((SelectInfo()&iMask)==iMask);
900 Bool_t AliAnalysisHelperJetTasks::TestEventClass(Int_t iMask){
901 if(iMask==0)return kTRUE;
902 return (EventClass()==iMask);
906 UInt_t AliAnalysisHelperJetTasks::SelectInfo(Bool_t bSet,UInt_t iNew){
908 // set event by event the slection info
911 static UInt_t iSelectInfo = 0; //
919 Int_t AliAnalysisHelperJetTasks::EventClass(Bool_t bSet,Int_t iNew){
921 // gloab storage/access to event class
924 static Int_t iEventClass = 0; //
934 //___________________________________________________________________________________________________________
936 Bool_t AliAnalysisHelperJetTasks::GetEventShapes(TVector3 &n01,const TVector3 * pTrack, Int_t nTracks, Double_t * eventShapes)
939 // Event shape calculation
940 // sona.pochybova@cern.ch
942 const Int_t kTracks = 1000;
943 if(nTracks>kTracks)return kFALSE;
945 //variables for thrust calculation
946 TVector3 pTrackPerp[kTracks];
954 Double_t psum102 = 0;
955 Double_t psum103 = 0;
957 Double_t thrust[kTracks] = {0.0};
959 Double_t thrust02[kTracks] = {0.0};
961 Double_t thrust03[kTracks] = {0.0};
964 //Sphericity calculation variables
983 //loop for thrust calculation
986 for(Int_t i = 0; i < nTracks; i++)
988 pTrackPerp[i].SetXYZ(pTrack[i].X(), pTrack[i].Y(), 0);
989 psum2 += pTrackPerp[i].Mag();
992 //additional starting axis
994 n02 = pTrack[1].Unit();
997 n03 = pTrack[2].Unit();
1000 //switches for calculating thrust for different starting points
1005 //indexes for iteration of different starting points
1010 //maximal number of iterations
1011 // Int_t nMaxIter = 100;
1013 for(Int_t k = 0; k < nTracks; k++)
1017 psum.SetXYZ(0., 0., 0.);
1019 for(Int_t i = 0; i < nTracks; i++)
1021 psum1 += (TMath::Abs(n01.Dot(pTrackPerp[i])));
1022 if (n01.Dot(pTrackPerp[i]) > 0) psum += pTrackPerp[i];
1023 if (n01.Dot(pTrackPerp[i]) < 0) psum -= pTrackPerp[i];
1025 thrust[l1] = psum1/psum2;
1029 psum02.SetXYZ(0., 0., 0.);
1031 for(Int_t i = 0; i < nTracks; i++)
1033 psum102 += (TMath::Abs(n02.Dot(pTrackPerp[i])));
1034 if (n02.Dot(pTrackPerp[i]) > 0) psum02 += pTrackPerp[i];
1035 if (n02.Dot(pTrackPerp[i]) < 0) psum02 -= pTrackPerp[i];
1037 thrust02[l2] = psum102/psum2;
1041 psum03.SetXYZ(0., 0., 0.);
1043 for(Int_t i = 0; i < nTracks; i++)
1045 psum103 += (TMath::Abs(n03.Dot(pTrackPerp[i])));
1046 if (n03.Dot(pTrackPerp[i]) > 0) psum03 += pTrackPerp[i];
1047 if (n03.Dot(pTrackPerp[i]) < 0) psum03 -= pTrackPerp[i];
1049 thrust03[l3] = psum103/psum2;
1052 //check whether thrust value converged
1053 if(TMath::Abs(th-thrust[l1]) < 10e-7){
1057 if(TMath::Abs(th02-thrust02[l2]) < 10e-7){
1061 if(TMath::Abs(th03-thrust03[l3]) < 10e-7){
1065 //if it didn't, continue with the calculation
1073 th02 = thrust02[l2];
1074 n02 = psum02.Unit();
1079 th03 = thrust03[l3];
1080 n03 = psum03.Unit();
1084 //if thrust values for all starting direction converged check if to the same value
1085 if(switch2 == 0 && switch1 == 0 && switch3 == 0){
1086 if(TMath::Abs(th-th02) < 10e-7 && TMath::Abs(th-th03) < 10e-7 && TMath::Abs(th02-th03) < 10e-7){
1087 eventShapes[0] = th;
1088 AliInfoGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),Form("===== THRUST VALUE FOUND AT %d :: %f\n", k, th));
1091 //if they did not, reset switches
1102 // Printf("========== %d +++ th :: %f=============\n", l1, th);
1103 // Printf("========== %d +++ th2 :: %f=============\n", l2, th02);
1104 // Printf("========== %d +++ th3 :: %f=============\n", l3, th03);
1108 //if no common limitng value was found, take the maximum and take the corresponding thrust axis
1109 if(switch1 == 1 && switch2 == 1 && switch3 == 1){
1110 eventShapes[0] = TMath::Max(thrust[l1-1], thrust02[l2-1]);
1111 eventShapes[0] = TMath::Max(eventShapes[0], thrust03[l3-1]);
1112 if(TMath::Abs(eventShapes[0]-thrust[l1-1]) < 10e-7)
1114 if(TMath::Abs(eventShapes[0]-thrust02[l2-1]) < 10e-7)
1116 if(TMath::Abs(eventShapes[0]-thrust03[l3-1]) < 10e-7)
1118 Printf("NO LIMITING VALUE FOUND :: MAXIMUM = %f\n", eventShapes[0]);
1122 //other event shapes variables
1124 for(Int_t j = 0; j < nTracks; j++)
1126 s00 = s00 + (pTrack[j].Px()*pTrack[j].Px())/pTrack[j].Mag();
1127 s01 = s01 + (pTrack[j].Px()*pTrack[j].Py())/pTrack[j].Mag();
1128 s02 = s02 + (pTrack[j].Px()*pTrack[j].Pz())/pTrack[j].Mag();
1130 s10 = s10 + (pTrack[j].Py()*pTrack[j].Px())/pTrack[j].Mag();
1131 s11 = s11 + (pTrack[j].Py()*pTrack[j].Py())/pTrack[j].Mag();
1132 s12 = s12 + (pTrack[j].Py()*pTrack[j].Pz())/pTrack[j].Mag();
1134 s20 = s20 + (pTrack[j].Pz()*pTrack[j].Px())/pTrack[j].Mag();
1135 s21 = s21 + (pTrack[j].Pz()*pTrack[j].Py())/pTrack[j].Mag();
1136 s22 = s22 + (pTrack[j].Pz()*pTrack[j].Pz())/pTrack[j].Mag();
1138 ptot += pTrack[j].Mag();
1155 TMatrixDSymEigen eigen(m);
1156 TVectorD eigenVal = eigen.GetEigenValues();
1158 Double_t sphericity = (3/2)*(eigenVal(2)+eigenVal(1));
1159 eventShapes[1] = sphericity;
1161 Double_t aplanarity = (3/2)*(eigenVal(2));
1162 eventShapes[2] = aplanarity;
1164 c = 3*(eigenVal(0)*eigenVal(1)+eigenVal(0)*eigenVal(2)+eigenVal(1)*eigenVal(2));
1172 //__________________________________________________________________________________________________________________________
1173 // Trigger Decisions copid from PWG0/AliTriggerAnalysis
1176 Bool_t AliAnalysisHelperJetTasks::IsTriggerFired(const AliVEvent* aEv, Trigger trigger)
1178 // checks if an event has been triggered
1179 // no usage of ofline trigger here yet
1181 // here we do a dirty hack to take also into account the
1182 // missing trigger bits and Bunch crossing paatern for real data
1185 if(aEv->InheritsFrom("AliESDEvent")){
1186 const AliESDEvent *esd = (AliESDEvent*)aEv;
1196 if(esd->GetFiredTriggerClasses().Contains("CINT1B-"))return kTRUE;
1197 // does the same but without or'ed V0s
1198 if(esd->GetFiredTriggerClasses().Contains("CSMBB"))return kTRUE;
1199 if(esd->GetFiredTriggerClasses().Contains("CINT6B-"))return kTRUE;
1200 // this is for simulated data
1201 if(esd->GetFiredTriggerClasses().Contains("MB1"))return kTRUE;
1206 if(esd->GetFiredTriggerClasses().Contains("MB2"))return kTRUE;
1211 if(esd->GetFiredTriggerClasses().Contains("MB3"))return kTRUE;
1216 if(esd->GetFiredTriggerClasses().Contains("CSMBB"))return kTRUE;
1217 if(esd->GetFiredTriggerClasses().Contains("CINT6B-"))return kTRUE;
1218 if(esd->GetFiredTriggerClasses().Contains("GFO"))return kTRUE;
1223 Printf("IsEventTriggered: ERROR: Trigger type %d not implemented in this method", (Int_t) trigger);
1228 else if(aEv->InheritsFrom("AliAODEvent")){
1229 const AliAODEvent *aod = (AliAODEvent*)aEv;
1239 if(aod->GetFiredTriggerClasses().Contains("CINT1B"))return kTRUE;
1240 // does the same but without or'ed V0s
1241 if(aod->GetFiredTriggerClasses().Contains("CSMBB"))return kTRUE;
1243 if(aod->GetFiredTriggerClasses().Contains("MB1"))return kTRUE;
1248 if(aod->GetFiredTriggerClasses().Contains("MB2"))return kTRUE;
1253 if(aod->GetFiredTriggerClasses().Contains("MB3"))return kTRUE;
1258 if(aod->GetFiredTriggerClasses().Contains("CSMBB"))return kTRUE;
1259 if(aod->GetFiredTriggerClasses().Contains("GFO"))return kTRUE;
1264 Printf("IsEventTriggered: ERROR: Trigger type %d not implemented in this method", (Int_t) trigger);
1273 AliAnalysisHelperJetTasks::MCProcessType AliAnalysisHelperJetTasks::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
1275 // fetch the process type from the mc header
1279 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader);
1281 if (!pythiaGenHeader) {
1282 // printf(" AliAnalysisHelperJetTasks::GetProcessType : Unknown gen Header type). \n");
1283 return kInvalidProcess;
1287 Int_t pythiaType = pythiaGenHeader->ProcessType();
1288 fgLastProcessType = pythiaType;
1289 MCProcessType globalType = kInvalidProcess;
1293 printf(" AliAnalysisHelperJetTasks::GetProcessType : Pythia process type found: %d \n",pythiaType);
1297 if(pythiaType==92||pythiaType==93){
1300 else if(pythiaType==94){
1303 //else if(pythiaType != 91){ // also exclude elastic to be sure... CKB??
1311 AliAnalysisHelperJetTasks::MCProcessType AliAnalysisHelperJetTasks::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
1313 // get the process type of the event.
1316 // can only read pythia headers, either directly or from cocktalil header
1317 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader);
1319 if (!dpmJetGenHeader) {
1320 printf(" AliAnalysisHelperJetTasks::GetDPMjetProcessType : Unknown header type (not DPMjet or). \n");
1321 return kInvalidProcess;
1324 Int_t dpmJetType = dpmJetGenHeader->ProcessType();
1325 fgLastProcessType = dpmJetType;
1326 MCProcessType globalType = kInvalidProcess;
1330 printf(" AliAnalysisHelperJetTasks::GetDPMJetProcessType : DPMJet process type found: %d \n",dpmJetType);
1334 if (dpmJetType == 1 || dpmJetType == 4) { // explicitly inelastic plus central diffraction
1337 else if (dpmJetType==5 || dpmJetType==6) {
1340 else if (dpmJetType==7) {
1347 Int_t AliAnalysisHelperJetTasks::GetPhiBin(Double_t phi,Int_t fNRPBins)
1350 // Method to get phi bin o reaction plane
1353 if(!(TMath::Abs(phi)<=2*TMath::Pi()))return -1;
1354 Double_t phiwrtrp=TMath::ACos(TMath::Abs(TMath::Cos(phi)));
1355 phibin=Int_t(fNRPBins*phiwrtrp/(0.5*TMath::Pi()));
1359 Double_t AliAnalysisHelperJetTasks::ReactionPlane(Bool_t bSet,Double_t fNew){
1361 // Static helper task, (re)set event by event
1365 static Double_t fRP = 0; // if service task is not run we acccpet all