3 #include "TDirectory.h"
12 #include "AliMCEvent.h"
14 #include "AliESDEvent.h"
15 #include "AliAODJet.h"
16 #include "AliAODEvent.h"
18 #include "AliGenEventHeader.h"
19 #include "AliGenCocktailEventHeader.h"
20 #include "AliGenPythiaEventHeader.h"
23 #include "AliAnalysisHelperJetTasks.h"
24 #include "TMatrixDSym.h"
25 #include "TMatrixDSymEigen.h"
28 ClassImp(AliAnalysisHelperJetTasks)
33 AliGenPythiaEventHeader* AliAnalysisHelperJetTasks::GetPythiaEventHeader(AliMCEvent *mcEvent){
35 AliGenEventHeader* genHeader = mcEvent->GenEventHeader();
36 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(genHeader);
39 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(genHeader);
41 if (!genCocktailHeader) {
42 AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Unknown header type (not Pythia or Cocktail)");
43 // AliWarning(Form("%s %d: Unknown header type (not Pythia or Cocktail)",(char*)__FILE__,__LINE__));
46 TList* headerList = genCocktailHeader->GetHeaders();
47 for (Int_t i=0; i<headerList->GetEntries(); i++) {
48 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
53 AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Pythia event header not found");
57 return pythiaGenHeader;
62 void AliAnalysisHelperJetTasks::PrintStack(AliMCEvent *mcEvent,Int_t iFirst,Int_t iLast,Int_t iMaxPrint){
64 AliStack *stack = mcEvent->Stack();
66 Printf("%s%d No Stack available",(char*)__FILE__,__LINE__);
70 static Int_t iCount = 0;
71 if(iCount>iMaxPrint)return;
72 Int_t nStack = stack->GetNtrack();
73 if(iLast == 0)iLast = nStack;
74 else if(iLast > nStack)iLast = nStack;
77 Printf("####################################################################");
78 for(Int_t np = iFirst;np<iLast;++np){
79 TParticle *p = stack->Particle(np);
80 Printf("Nr.%d --- Status %d ---- Mother1 %d Mother2 %d Daughter1 %d Daughter2 %d ",
81 np,p->GetStatusCode(),p->GetMother(0),p->GetMother(1),p->GetDaughter(0),p->GetDaughter(1));
82 Printf("Eta %3.3f Phi %3.3f ",p->Eta(),p->Phi());
84 Printf("---------------------------------------");
92 void AliAnalysisHelperJetTasks::GetClosestJets(AliAODJet *genJets,const Int_t &kGenJets,
93 AliAODJet *recJets,const Int_t &kRecJets,
94 Int_t *iGenIndex,Int_t *iRecIndex,
95 Int_t iDebug,Float_t maxDist){
98 // Relate the two input jet Arrays
102 // The association has to be unique
103 // So check in two directions
104 // find the closest rec to a gen
105 // and check if there is no other rec which is closer
106 // Caveat: Close low energy/split jets may disturb this correlation
109 // Idea: search in two directions generated e.g (a--e) and rec (1--3)
110 // Fill a matrix with Flags (1 for closest rec jet, 2 for closest rec jet
111 // in the end we have something like this
125 // Only entries with "3" match from both sides
127 // In case we have more jets than kmaxjets only the
128 // first kmaxjets are searched
130 // use kMaxJets for a test not to fragemnt the memory...
132 for(int i = 0;i < kGenJets;++i)iGenIndex[i] = -1;
133 for(int j = 0;j < kRecJets;++j)iRecIndex[j] = -1;
139 const Int_t nGenJets = TMath::Min(kMaxJets,kGenJets);
140 const Int_t nRecJets = TMath::Min(kMaxJets,kRecJets);
142 if(nRecJets==0||nGenJets==0)return;
144 // UShort_t *iFlag = new UShort_t[nGenJets*nRecJets];
145 UShort_t iFlag[kMaxJets*kMaxJets];
146 for(int i = 0;i < nGenJets;++i){
147 for(int j = 0;j < nRecJets;++j){
148 iFlag[i*nGenJets+j] = 0;
154 // find the closest distance to the generated
155 for(int ig = 0;ig<nGenJets;++ig){
156 Float_t dist = maxDist;
157 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());
158 for(int ir = 0;ir<nRecJets;++ir){
159 Double_t dR = genJets[ig].DeltaR(&recJets[ir]);
160 if(iDebug>1)Printf("Rec (%d) p_T %3.3f eta %3.3f ph %3.3f ",ir,recJets[ir].Pt(),recJets[ir].Eta(),recJets[ir].Phi());
161 if(iDebug>1)Printf("Distance (%d)--(%d) %3.3f ",ig,ir,dR);
167 if(iRecIndex[ig]>=0)iFlag[ig*nGenJets+iRecIndex[ig]]+=1;
172 for(int ir = 0;ir<nRecJets;++ir){
173 Float_t dist = maxDist;
174 for(int ig = 0;ig<nGenJets;++ig){
175 Double_t dR = genJets[ig].DeltaR(&recJets[ir]);
181 if(iGenIndex[ir]>=0)iFlag[iGenIndex[ir]*nGenJets+ir]+=2;
186 // check for "true" correlations
188 if(iDebug>1)Printf(">>>>>> Matrix");
190 for(int ig = 0;ig<nGenJets;++ig){
191 for(int ir = 0;ir<nRecJets;++ir){
193 if(iDebug>1)printf("Flag[%d][%d] %d ",ig,ir,iFlag[ig*nGenJets+ir]);
196 // we have a uniqie correlation
197 if(iFlag[ig*nGenJets+ir]==3){
203 // we just take the correlation from on side
204 if((iFlag[ig*nGenJets+ir]&2)==2){
207 if((iFlag[ig*nGenJets+ir]&1)==1){
212 if(iDebug>1)printf("\n");
218 void AliAnalysisHelperJetTasks::MergeOutput(char* cFiles, char* cDir, char *cList,char *cOutFile,Bool_t bUpdate){
220 // This is used to merge the analysis-output from different
221 // data samples/pt_hard bins
222 // in case the eventweigth was set to xsection/ntrials already, this
223 // is not needed. Both methods only work in case we do not mix different
224 // pt_hard bins, and do not have overlapping bins
226 const Int_t nMaxBins = 12;
227 // LHC08q jetjet100: Mean = 1.42483e-03, RMS = 6.642e-05
228 // LHC08r jetjet50: Mean = 2.44068e-02, RMS = 1.144e-03
229 // LHC08v jetjet15-50: Mean = 2.168291 , RMS = 7.119e-02
230 // const Float_t xsection[nBins] = {2.168291,2.44068e-02};
232 Float_t xsection[nMaxBins];
233 Float_t nTrials[nMaxBins];
234 Float_t sf[nMaxBins];
235 TList *lIn[nMaxBins];
236 TDirectory *dIn[nMaxBins];
237 TFile *fIn[nMaxBins];
245 fIn[ibTotal] = TFile::Open(cFile);
247 dIn[ibTotal] = gDirectory;
250 dIn[ibTotal] = (TDirectory*)fIn[ibTotal]->Get(cDir);
253 Printf("%s:%d No directory %s found, exiting...",__FILE__,__LINE__,cDir);
258 lIn[ibTotal] = (TList*)dIn[ibTotal]->Get(cList);
259 Printf("Merging file %s %s",cFile, cDir);
261 Printf("%s:%d No list %s found, exiting...",__FILE__,__LINE__,cList);
265 TH1* hTrials = (TH1F*)lIn[ibTotal]->FindObject("fh1Trials");
267 Printf("%s:%d fh1PtHard_Trials not found in list, exiting...",__FILE__,__LINE__);
270 TProfile* hXsec = (TProfile*)lIn[ibTotal]->FindObject("fh1Xsec");
272 Printf("%s:%d fh1Xsec not found in list, exiting...",__FILE__,__LINE__);
275 xsection[ibTotal] = hXsec->GetBinContent(1);
276 nTrials[ibTotal] = hTrials->Integral();
277 sf[ibTotal] = xsection[ibTotal]/ nTrials[ibTotal];
282 Printf("%s:%d No files found for mergin, exiting",__FILE__,__LINE__);
287 if(bUpdate)fOut = new TFile(cOutFile,"UPDATE");
288 else fOut = new TFile(cOutFile,"RECREATE");
289 TDirectory *dOut = fOut->mkdir(dIn[0]->GetName());
291 TList *lOut = new TList();
292 lOut->SetName(lIn[0]->GetName());
294 // for the start scale all...
295 for(int ie = 0; ie < lIn[0]->GetEntries();++ie){
297 THnSparse *hnAdd = 0;
298 for(int ib = 0;ib < ibTotal;++ib){
299 // dynamic cast does not work with cint
300 TObject *h = lIn[ib]->At(ie);
301 if(h->InheritsFrom("TH1")){
304 h1Add = (TH1*)h1->Clone(h1->GetName());
305 h1Add->Scale(sf[ib]);
308 h1Add->Add(h1,sf[ib]);
311 else if(h->InheritsFrom("THnSparse")){
312 THnSparse *hn = (THnSparse*)h;
314 hnAdd = (THnSparse*)hn->Clone(hn->GetName());
315 hnAdd->Scale(sf[ib]);
318 hnAdd->Add(hn,sf[ib]);
324 if(h1Add)lOut->Add(h1Add);
325 else if(hnAdd)lOut->Add(hnAdd);
328 lOut->Write(lOut->GetName(),TObject::kSingleKey);
332 Bool_t AliAnalysisHelperJetTasks::PythiaInfoFromFile(const char* currFile,Float_t &fXsec,Float_t &fTrials){
334 // get the cross section and the trails either from pyxsec.root or from pysec_hists.root
335 // This is to called in Notify and should provide the path to the AOD/ESD file
337 TString file(currFile);
341 if(file.Contains("root_archive.zip#")){
342 Ssiz_t pos1 = file.Index("root_archive",12,TString::kExact);
343 Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
344 file.Replace(pos+1,20,"");
347 // not an archive take the basename....
348 file.ReplaceAll(gSystem->BaseName(file.Data()),"");
350 Printf("%s",file.Data());
355 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
357 // next trial fetch the histgram file
358 fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
360 // not a severe condition but inciate that we have no information
364 // find the tlist we want to be independtent of the name so use the Tkey
365 TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0);
370 TList *list = dynamic_cast<TList*>(key->ReadObj());
375 fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
376 fTrials = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
379 } // no tree pyxsec.root
381 TTree *xtree = (TTree*)fxsec->Get("Xsection");
387 Double_t xsection = 0;
388 xtree->SetBranchAddress("xsection",&xsection);
389 xtree->SetBranchAddress("ntrials",&ntrials);
398 Bool_t AliAnalysisHelperJetTasks::PrintDirectorySize(const char* currFile){
400 TFile *fIn = TFile::Open(currFile);
402 // not a severe condition but inciate that we have no information
405 // find the tlists we want to be independtent of the name so use the Tkey
406 TList* keyList = fIn->GetListOfKeys();
407 Float_t memorySize = 0;
408 Float_t diskSize = 0;
410 for(int i = 0;i < keyList->GetEntries();i++){
411 TKey* ikey = (TKey*)keyList->At(i);
413 // TList *list = dynamic_cast<TList*>(key->ReadObj());
414 // TNamed *name = dynamic_cast<TNamed*>(ikey->ReadObj());
415 TDirectory *dir = dynamic_cast<TDirectory*>(ikey->ReadObj());
421 Printf("%03d : %60s %8d %8d ",i,dir->GetName(),ikey->GetObjlen(),ikey->GetNbytes());
422 TList * dirKeyList = dir->GetListOfKeys();
423 for(int j = 0;j<dirKeyList->GetEntries();j++){
424 TKey* jkey = (TKey*)dirKeyList->At(j);
425 TList *list = dynamic_cast<TList*>(jkey->ReadObj());
427 memorySize += (Float_t)jkey->GetObjlen()/1024./1024.;
428 diskSize += (Float_t)jkey->GetNbytes()/1024./1024.;
430 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.);
433 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.);
438 Printf("Total %5.2f MB %5.2f MB",memorySize,diskSize);
443 Bool_t AliAnalysisHelperJetTasks::Selected(Bool_t bSet,Bool_t bNew){
444 static Bool_t bSelected = kTRUE; // if service task is not run we acccpet all
451 //___________________________________________________________________________________________________________
453 Bool_t AliAnalysisHelperJetTasks::GetEventShapes(TVector3 &n01, TVector3 * pTrack, Int_t nTracks, Double_t * eventShapes)
456 // Event shape calculation
457 // sona.pochybova@cern.ch
459 const Int_t kTracks = 1000;
460 if(nTracks>kTracks)return kFALSE;
462 //variables for thrust calculation
463 TVector3 pTrackPerp[kTracks];
471 Double_t psum102 = 0;
472 Double_t psum103 = 0;
474 Double_t thrust[kTracks];
476 Double_t thrust02[kTracks];
478 Double_t thrust03[kTracks];
481 //Sphericity calculation variables
500 //loop for thrust calculation
503 for(Int_t i = 0; i < nTracks; i++)
505 pTrackPerp[i].SetXYZ(pTrack[i].X(), pTrack[i].Y(), 0);
506 psum2 += pTrackPerp[i].Mag();
509 //additional starting axis
511 n02 = pTrack[1].Unit();
514 n03 = pTrack[2].Unit();
517 //switches for calculating thrust for different starting points
522 //indexes for iteration of different starting points
527 //maximal number of iterations
528 // Int_t nMaxIter = 100;
530 for(Int_t k = 0; k < nTracks; k++)
534 psum.SetXYZ(0., 0., 0.);
536 for(Int_t i = 0; i < nTracks; i++)
538 psum1 += (TMath::Abs(n01.Dot(pTrackPerp[i])));
539 if (n01.Dot(pTrackPerp[i]) > 0) psum += pTrackPerp[i];
540 if (n01.Dot(pTrackPerp[i]) < 0) psum -= pTrackPerp[i];
542 thrust[l1] = psum1/psum2;
546 psum02.SetXYZ(0., 0., 0.);
548 for(Int_t i = 0; i < nTracks; i++)
550 psum102 += (TMath::Abs(n02.Dot(pTrackPerp[i])));
551 if (n02.Dot(pTrackPerp[i]) > 0) psum02 += pTrackPerp[i];
552 if (n02.Dot(pTrackPerp[i]) < 0) psum02 -= pTrackPerp[i];
554 thrust02[l2] = psum102/psum2;
558 psum03.SetXYZ(0., 0., 0.);
560 for(Int_t i = 0; i < nTracks; i++)
562 psum103 += (TMath::Abs(n03.Dot(pTrackPerp[i])));
563 if (n03.Dot(pTrackPerp[i]) > 0) psum03 += pTrackPerp[i];
564 if (n03.Dot(pTrackPerp[i]) < 0) psum03 -= pTrackPerp[i];
566 thrust03[l3] = psum103/psum2;
569 //check whether thrust value converged
570 if(TMath::Abs(th-thrust[l1]) < 10e-7){
574 if(TMath::Abs(th02-thrust02[l2]) < 10e-7){
578 if(TMath::Abs(th03-thrust03[l3]) < 10e-7){
582 //if it didn't, continue with the calculation
601 //if thrust values for all starting direction converged check if to the same value
602 if(switch2 == 0 && switch1 == 0 && switch3 == 0){
603 if(TMath::Abs(th-th02) < 10e-7 && TMath::Abs(th-th03) < 10e-7 && TMath::Abs(th02-th03) < 10e-7){
605 AliInfoGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),Form("===== THRUST VALUE FOUND AT %d :: %f\n", k, th));
608 //if they did not, reset switches
619 // Printf("========== %d +++ th :: %f=============\n", l1, th);
620 // Printf("========== %d +++ th2 :: %f=============\n", l2, th02);
621 // Printf("========== %d +++ th3 :: %f=============\n", l3, th03);
625 //if no common limitng value was found, take the maximum and take the corresponding thrust axis
626 if(switch1 == 1 && switch2 == 1 && switch3 == 1){
627 eventShapes[0] = TMath::Max(thrust[l1-1], thrust02[l2-1]);
628 eventShapes[0] = TMath::Max(eventShapes[0], thrust03[l3-1]);
629 if(TMath::Abs(eventShapes[0]-thrust[l1-1]) < 10e-7)
631 if(TMath::Abs(eventShapes[0]-thrust02[l2-1]) < 10e-7)
633 if(TMath::Abs(eventShapes[0]-thrust03[l3-1]) < 10e-7)
635 Printf("NO LIMITING VALUE FOUND :: MAXIMUM = %f\n", eventShapes[0]);
639 //other event shapes variables
641 for(Int_t j = 0; j < nTracks; j++)
643 s00 = s00 + (pTrack[j].Px()*pTrack[j].Px())/pTrack[j].Mag();
644 s01 = s01 + (pTrack[j].Px()*pTrack[j].Py())/pTrack[j].Mag();
645 s02 = s02 + (pTrack[j].Px()*pTrack[j].Pz())/pTrack[j].Mag();
647 s10 = s10 + (pTrack[j].Py()*pTrack[j].Px())/pTrack[j].Mag();
648 s11 = s11 + (pTrack[j].Py()*pTrack[j].Py())/pTrack[j].Mag();
649 s12 = s12 + (pTrack[j].Py()*pTrack[j].Pz())/pTrack[j].Mag();
651 s20 = s20 + (pTrack[j].Pz()*pTrack[j].Px())/pTrack[j].Mag();
652 s21 = s21 + (pTrack[j].Pz()*pTrack[j].Py())/pTrack[j].Mag();
653 s22 = s22 + (pTrack[j].Pz()*pTrack[j].Pz())/pTrack[j].Mag();
655 ptot += pTrack[j].Mag();
672 TMatrixDSymEigen eigen(m);
673 TVectorD eigenVal = eigen.GetEigenValues();
675 Double_t sphericity = (3/2)*(eigenVal(2)+eigenVal(1));
676 eventShapes[1] = sphericity;
678 Double_t aplanarity = (3/2)*(eigenVal(2));
679 eventShapes[2] = aplanarity;
681 c = 3*(eigenVal(0)*eigenVal(1)+eigenVal(0)*eigenVal(2)+eigenVal(1)*eigenVal(2));
689 //__________________________________________________________________________________________________________________________
690 // Trigger Decisions copid from PWG0/AliTriggerAnalysis
693 Bool_t AliAnalysisHelperJetTasks::IsTriggerFired(const AliVEvent* aEv, Trigger trigger)
695 // checks if an event has been triggered
696 // no usage of ofline trigger here yet
698 // here we do a dirty hack to take also into account the
699 // missing trigger bits and Bunch crossing paatern for real data
702 if(aEv->InheritsFrom("AliESDEvent")){
703 const AliESDEvent *esd = (AliESDEvent*)aEv;
713 if(esd->GetFiredTriggerClasses().Contains("CINT1B-"))return kTRUE;
714 // does the same but without or'ed V0s
715 if(esd->GetFiredTriggerClasses().Contains("CSMBB"))return kTRUE;
716 if(esd->GetFiredTriggerClasses().Contains("CINT6B-"))return kTRUE;
717 // this is for simulated data
718 if(esd->GetFiredTriggerClasses().Contains("MB1"))return kTRUE;
723 if(esd->GetFiredTriggerClasses().Contains("MB2"))return kTRUE;
728 if(esd->GetFiredTriggerClasses().Contains("MB3"))return kTRUE;
733 if(esd->GetFiredTriggerClasses().Contains("CSMBB"))return kTRUE;
734 if(esd->GetFiredTriggerClasses().Contains("CINT6B-"))return kTRUE;
735 if(esd->GetFiredTriggerClasses().Contains("GFO"))return kTRUE;
740 Printf("IsEventTriggered: ERROR: Trigger type %d not implemented in this method", (Int_t) trigger);
745 else if(aEv->InheritsFrom("AliAODEvent")){
746 const AliAODEvent *aod = (AliAODEvent*)aEv;
756 if(aod->GetFiredTriggerClasses().Contains("CINT1B"))return kTRUE;
757 // does the same but without or'ed V0s
758 if(aod->GetFiredTriggerClasses().Contains("CSMBB"))return kTRUE;
760 if(aod->GetFiredTriggerClasses().Contains("MB1"))return kTRUE;
765 if(aod->GetFiredTriggerClasses().Contains("MB2"))return kTRUE;
770 if(aod->GetFiredTriggerClasses().Contains("MB3"))return kTRUE;
775 if(aod->GetFiredTriggerClasses().Contains("CSMBB"))return kTRUE;
776 if(aod->GetFiredTriggerClasses().Contains("GFO"))return kTRUE;
781 Printf("IsEventTriggered: ERROR: Trigger type %d not implemented in this method", (Int_t) trigger);