11 #include "AliMCEvent.h"
13 #include "AliAODJet.h"
15 #include "AliGenEventHeader.h"
16 #include "AliGenCocktailEventHeader.h"
17 #include "AliGenPythiaEventHeader.h"
20 #include "AliAnalysisHelperJetTasks.h"
21 #include "TMatrixDSym.h"
22 #include "TMatrixDSymEigen.h"
25 ClassImp(AliAnalysisHelperJetTasks)
30 AliGenPythiaEventHeader* AliAnalysisHelperJetTasks::GetPythiaEventHeader(AliMCEvent *mcEvent){
32 AliGenEventHeader* genHeader = mcEvent->GenEventHeader();
33 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(genHeader);
36 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(genHeader);
38 if (!genCocktailHeader) {
39 AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Unknown header type (not Pythia or Cocktail)");
40 // AliWarning(Form("%s %d: Unknown header type (not Pythia or Cocktail)",(char*)__FILE__,__LINE__));
43 TList* headerList = genCocktailHeader->GetHeaders();
44 for (Int_t i=0; i<headerList->GetEntries(); i++) {
45 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
50 AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Pythia event header not found");
54 return pythiaGenHeader;
59 void AliAnalysisHelperJetTasks::PrintStack(AliMCEvent *mcEvent,Int_t iFirst,Int_t iLast,Int_t iMaxPrint){
61 AliStack *stack = mcEvent->Stack();
63 Printf("%s%d No Stack available",(char*)__FILE__,__LINE__);
67 static Int_t iCount = 0;
68 if(iCount>iMaxPrint)return;
69 Int_t nStack = stack->GetNtrack();
70 if(iLast == 0)iLast = nStack;
71 else if(iLast > nStack)iLast = nStack;
74 Printf("####################################################################");
75 for(Int_t np = iFirst;np<iLast;++np){
76 TParticle *p = stack->Particle(np);
77 Printf("Nr.%d --- Status %d ---- Mother1 %d Mother2 %d Daughter1 %d Daughter2 %d ",
78 np,p->GetStatusCode(),p->GetMother(0),p->GetMother(1),p->GetDaughter(0),p->GetDaughter(1));
79 Printf("Eta %3.3f Phi %3.3f ",p->Eta(),p->Phi());
81 Printf("---------------------------------------");
89 void AliAnalysisHelperJetTasks::GetClosestJets(AliAODJet *genJets,const Int_t &kGenJets,
90 AliAODJet *recJets,const Int_t &kRecJets,
91 Int_t *iGenIndex,Int_t *iRecIndex,
92 Int_t iDebug,Float_t maxDist){
95 // Relate the two input jet Arrays
99 // The association has to be unique
100 // So check in two directions
101 // find the closest rec to a gen
102 // and check if there is no other rec which is closer
103 // Caveat: Close low energy/split jets may disturb this correlation
106 // Idea: search in two directions generated e.g (a--e) and rec (1--3)
107 // Fill a matrix with Flags (1 for closest rec jet, 2 for closest rec jet
108 // in the end we have something like this
122 // Only entries with "3" match from both sides
124 // In case we have more jets than kmaxjets only the
125 // first kmaxjets are searched
127 // use kMaxJets for a test not to fragemnt the memory...
129 for(int i = 0;i < kGenJets;++i)iGenIndex[i] = -1;
130 for(int j = 0;j < kRecJets;++j)iRecIndex[j] = -1;
136 const Int_t nGenJets = TMath::Min(kMaxJets,kGenJets);
137 const Int_t nRecJets = TMath::Min(kMaxJets,kRecJets);
139 if(nRecJets==0||nGenJets==0)return;
141 // UShort_t *iFlag = new UShort_t[nGenJets*nRecJets];
142 UShort_t iFlag[kMaxJets*kMaxJets];
143 for(int i = 0;i < nGenJets;++i){
144 for(int j = 0;j < nRecJets;++j){
145 iFlag[i*nGenJets+j] = 0;
151 // find the closest distance to the generated
152 for(int ig = 0;ig<nGenJets;++ig){
153 Float_t dist = maxDist;
154 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());
155 for(int ir = 0;ir<nRecJets;++ir){
156 Double_t dR = genJets[ig].DeltaR(&recJets[ir]);
157 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());
158 if(iDebug>1)Printf("Distance (%d)--(%d) %3.3f ",ig,ir,dR);
164 if(iRecIndex[ig]>=0)iFlag[ig*nGenJets+iRecIndex[ig]]+=1;
169 for(int ir = 0;ir<nRecJets;++ir){
170 Float_t dist = maxDist;
171 for(int ig = 0;ig<nGenJets;++ig){
172 Double_t dR = genJets[ig].DeltaR(&recJets[ir]);
178 if(iGenIndex[ir]>=0)iFlag[iGenIndex[ir]*nGenJets+ir]+=2;
183 // check for "true" correlations
185 if(iDebug>1)Printf(">>>>>> Matrix");
187 for(int ig = 0;ig<nGenJets;++ig){
188 for(int ir = 0;ir<nRecJets;++ir){
190 if(iDebug>1)printf("Flag[%d][%d] %d ",ig,ir,iFlag[ig*nGenJets+ir]);
193 // we have a uniqie correlation
194 if(iFlag[ig*nGenJets+ir]==3){
200 // we just take the correlation from on side
201 if((iFlag[ig*nGenJets+ir]&2)==2){
204 if((iFlag[ig*nGenJets+ir]&1)==1){
209 if(iDebug>1)printf("\n");
215 void AliAnalysisHelperJetTasks::MergeOutput(char* cFiles, char* cList){
217 // This is used to merge the analysis-output from different
218 // data samples/pt_hard bins
219 // in case the eventweigth was set to xsection/ntrials already, this
220 // is not needed. Both methods only work in case we do not mix different
221 // pt_hard bins, and do not have overlapping bins
223 const Int_t nMaxBins = 12;
224 // LHC08q jetjet100: Mean = 1.42483e-03, RMS = 6.642e-05
225 // LHC08r jetjet50: Mean = 2.44068e-02, RMS = 1.144e-03
226 // LHC08v jetjet15-50: Mean = 2.168291 , RMS = 7.119e-02
227 // const Float_t xsection[nBins] = {2.168291,2.44068e-02};
229 Float_t xsection[nMaxBins];
230 Float_t nTrials[nMaxBins];
231 Float_t sf[nMaxBins];
232 TList *lIn[nMaxBins];
233 TFile *fIn[nMaxBins];
241 fIn[ibTotal] = TFile::Open(cFile);
242 lIn[ibTotal] = (TList*)fIn[ibTotal]->Get(cList);
243 Printf("Merging file %s",cFile);
245 Printf("%s:%d No list %s found, exiting...",__FILE__,__LINE__,cList);
249 TH1* hTrials = (TH1F*)lIn[ibTotal]->FindObject("fh1Trials");
251 Printf("%s:%d fh1PtHard_Trials not found in list, exiting...",__FILE__,__LINE__);
254 TProfile* hXsec = (TProfile*)lIn[ibTotal]->FindObject("fh1Xsec");
256 Printf("%s:%d fh1Xsec not found in list, exiting...",__FILE__,__LINE__);
259 xsection[ibTotal] = hXsec->GetBinContent(1);
260 nTrials[ibTotal] = hTrials->Integral();
261 sf[ibTotal] = xsection[ibTotal]/ nTrials[ibTotal];
266 Printf("%s:%d No files found for mergin, exiting",__FILE__,__LINE__);
270 TFile *fOut = new TFile("allpt.root","RECREATE");
271 TList *lOut = new TList();
272 lOut->SetName(lIn[0]->GetName());
273 // for the start scale all...
274 for(int ie = 0; ie < lIn[0]->GetEntries();++ie){
276 THnSparse *hnAdd = 0;
277 for(int ib = 0;ib < ibTotal;++ib){
278 // dynamic cast does not work with cint
279 TObject *h = lIn[ib]->At(ie);
280 if(h->InheritsFrom("TH1")){
283 h1Add = (TH1*)h1->Clone(h1->GetName());
284 h1Add->Scale(sf[ib]);
287 h1Add->Add(h1,sf[ib]);
290 else if(h->InheritsFrom("THnSparse")){
291 THnSparse *hn = (THnSparse*)h;
293 hnAdd = (THnSparse*)hn->Clone(hn->GetName());
294 hnAdd->Scale(sf[ib]);
297 hnAdd->Add(hn,sf[ib]);
303 if(h1Add)lOut->Add(h1Add);
304 else if(hnAdd)lOut->Add(hnAdd);
307 lOut->Write(lOut->GetName(),TObject::kSingleKey);
311 Bool_t AliAnalysisHelperJetTasks::PythiaInfoFromFile(const char* currFile,Float_t &fXsec,Float_t &fTrials){
313 // get the cross section and the trails either from pyxsec.root or from pysec_hists.root
314 // This is to called in Notify and should provide the path to the AOD/ESD file
316 TString file(currFile);
320 if(file.Contains("root_archive.zip#")){
321 Ssiz_t pos1 = file.Index("root_archive",12,TString::kExact);
322 Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
323 file.Replace(pos+1,20,"");
326 // not an archive take the basename....
327 file.ReplaceAll(gSystem->BaseName(file.Data()),"");
329 Printf("%s",file.Data());
334 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
336 // next trial fetch the histgram file
337 fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
339 // not a severe condition but inciate that we have no information
343 // find the tlist we want to be independtent of the name so use the Tkey
344 TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0);
349 TList *list = dynamic_cast<TList*>(key->ReadObj());
354 fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
355 fTrials = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
358 } // no tree pyxsec.root
360 TTree *xtree = (TTree*)fxsec->Get("Xsection");
366 Double_t xsection = 0;
367 xtree->SetBranchAddress("xsection",&xsection);
368 xtree->SetBranchAddress("ntrials",&ntrials);
378 Bool_t AliAnalysisHelperJetTasks::GetThrustAxis(TVector3 &n01, TVector3 * pTrack, const Int_t &nTracks)
381 // fetch the thrust axis
382 // sona.pochybova@cern.ch
384 const Int_t kTracks = 1000;
385 if(nTracks>kTracks)return kFALSE;
390 Double_t thrust[kTracks];
396 // for(Int_t j = 0; j < nTracks; j++)
397 while(TMath::Abs(th-tpom) > 10e-7 && j < nTracks)
400 psum.SetXYZ(0., 0., 0.);
403 for(Int_t i = 0; i < nTracks; i++)
405 psum1 += (TMath::Abs(n01.Dot(pTrack[i])));
406 psum2 += pTrack[i].Mag();
408 if (n01.Dot(pTrack[i]) > 0) psum += pTrack[i];
409 if (n01.Dot(pTrack[i]) < 0) psum -= pTrack[i];
412 thrust[j] = psum1/psum2;
414 // if(th == thrust[j])
425 //___________________________________________________________________________________________________________
427 Bool_t AliAnalysisHelperJetTasks::GetEventShapes(TVector3 &n01, TVector3 * pTrack, Int_t nTracks, Double_t * eventShapes)
430 // Event shape calculation
431 // sona.pochybova@cern.ch
433 const Int_t kTracks = 1000;
434 if(nTracks>kTracks)return kFALSE;
437 TVector3 pTrackPerp[kTracks];
440 Double_t thrust[kTracks];
444 //Sphericity calculation
463 //loop for thrust calculation
466 while(TMath::Abs(th-tpom) > 10e-7 && k < nTracks)
469 psum.SetXYZ(0., 0., 0.);
472 for(Int_t i = 0; i < nTracks; i++)
474 pTrackPerp[i].SetXYZ(pTrack[i].X(), pTrack[i].Y(), 0);
476 psum1 += (TMath::Abs(n01.Dot(pTrackPerp[i])));
477 psum2 += pTrackPerp[i].Mag();
479 if (n01.Dot(pTrackPerp[i]) > 0) psum += pTrackPerp[i];
480 if (n01.Dot(pTrackPerp[i]) < 0) psum -= pTrackPerp[i];
483 thrust[k] = psum1/psum2;
488 // Printf("========== %d +++ th :: %f, tpom :: %f=============\n", k, th, tpom);
494 //other event shapes variables
496 for(Int_t j = 0; j < nTracks; j++)
498 s00 = s00 + (pTrack[j].Px()*pTrack[j].Px())/pTrack[j].Mag();
499 s01 = s01 + (pTrack[j].Px()*pTrack[j].Py())/pTrack[j].Mag();
500 s02 = s02 + (pTrack[j].Px()*pTrack[j].Pz())/pTrack[j].Mag();
502 s10 = s10 + (pTrack[j].Py()*pTrack[j].Px())/pTrack[j].Mag();
503 s11 = s11 + (pTrack[j].Py()*pTrack[j].Py())/pTrack[j].Mag();
504 s12 = s12 + (pTrack[j].Py()*pTrack[j].Pz())/pTrack[j].Mag();
506 s20 = s20 + (pTrack[j].Pz()*pTrack[j].Px())/pTrack[j].Mag();
507 s21 = s21 + (pTrack[j].Pz()*pTrack[j].Py())/pTrack[j].Mag();
508 s22 = s22 + (pTrack[j].Pz()*pTrack[j].Pz())/pTrack[j].Mag();
510 ptot += pTrack[j].Mag();
527 TMatrixDSymEigen eigen(m);
528 TVectorD eigenVal = eigen.GetEigenValues();
530 Double_t sphericity = (3/2)*(eigenVal(2)+eigenVal(1));
531 eventShapes[1] = sphericity;
533 Double_t aplanarity = (3/2)*(eigenVal(2));
534 eventShapes[2] = aplanarity;
536 c = 3*(eigenVal(0)*eigenVal(1)+eigenVal(0)*eigenVal(2)+eigenVal(1)*eigenVal(2));
544 //__________________________________________________________________________________________________________________________