11 #include "AliMCEvent.h"
13 #include "AliESDEvent.h"
14 #include "AliAODJet.h"
16 #include "AliGenEventHeader.h"
17 #include "AliGenCocktailEventHeader.h"
18 #include "AliGenPythiaEventHeader.h"
21 #include "AliAnalysisHelperJetTasks.h"
22 #include "TMatrixDSym.h"
23 #include "TMatrixDSymEigen.h"
26 ClassImp(AliAnalysisHelperJetTasks)
31 AliGenPythiaEventHeader* AliAnalysisHelperJetTasks::GetPythiaEventHeader(AliMCEvent *mcEvent){
33 AliGenEventHeader* genHeader = mcEvent->GenEventHeader();
34 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(genHeader);
37 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(genHeader);
39 if (!genCocktailHeader) {
40 AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Unknown header type (not Pythia or Cocktail)");
41 // AliWarning(Form("%s %d: Unknown header type (not Pythia or Cocktail)",(char*)__FILE__,__LINE__));
44 TList* headerList = genCocktailHeader->GetHeaders();
45 for (Int_t i=0; i<headerList->GetEntries(); i++) {
46 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
51 AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Pythia event header not found");
55 return pythiaGenHeader;
60 void AliAnalysisHelperJetTasks::PrintStack(AliMCEvent *mcEvent,Int_t iFirst,Int_t iLast,Int_t iMaxPrint){
62 AliStack *stack = mcEvent->Stack();
64 Printf("%s%d No Stack available",(char*)__FILE__,__LINE__);
68 static Int_t iCount = 0;
69 if(iCount>iMaxPrint)return;
70 Int_t nStack = stack->GetNtrack();
71 if(iLast == 0)iLast = nStack;
72 else if(iLast > nStack)iLast = nStack;
75 Printf("####################################################################");
76 for(Int_t np = iFirst;np<iLast;++np){
77 TParticle *p = stack->Particle(np);
78 Printf("Nr.%d --- Status %d ---- Mother1 %d Mother2 %d Daughter1 %d Daughter2 %d ",
79 np,p->GetStatusCode(),p->GetMother(0),p->GetMother(1),p->GetDaughter(0),p->GetDaughter(1));
80 Printf("Eta %3.3f Phi %3.3f ",p->Eta(),p->Phi());
82 Printf("---------------------------------------");
90 void AliAnalysisHelperJetTasks::GetClosestJets(AliAODJet *genJets,const Int_t &kGenJets,
91 AliAODJet *recJets,const Int_t &kRecJets,
92 Int_t *iGenIndex,Int_t *iRecIndex,
93 Int_t iDebug,Float_t maxDist){
96 // Relate the two input jet Arrays
100 // The association has to be unique
101 // So check in two directions
102 // find the closest rec to a gen
103 // and check if there is no other rec which is closer
104 // Caveat: Close low energy/split jets may disturb this correlation
107 // Idea: search in two directions generated e.g (a--e) and rec (1--3)
108 // Fill a matrix with Flags (1 for closest rec jet, 2 for closest rec jet
109 // in the end we have something like this
123 // Only entries with "3" match from both sides
125 // In case we have more jets than kmaxjets only the
126 // first kmaxjets are searched
128 // use kMaxJets for a test not to fragemnt the memory...
130 for(int i = 0;i < kGenJets;++i)iGenIndex[i] = -1;
131 for(int j = 0;j < kRecJets;++j)iRecIndex[j] = -1;
137 const Int_t nGenJets = TMath::Min(kMaxJets,kGenJets);
138 const Int_t nRecJets = TMath::Min(kMaxJets,kRecJets);
140 if(nRecJets==0||nGenJets==0)return;
142 // UShort_t *iFlag = new UShort_t[nGenJets*nRecJets];
143 UShort_t iFlag[kMaxJets*kMaxJets];
144 for(int i = 0;i < nGenJets;++i){
145 for(int j = 0;j < nRecJets;++j){
146 iFlag[i*nGenJets+j] = 0;
152 // find the closest distance to the generated
153 for(int ig = 0;ig<nGenJets;++ig){
154 Float_t dist = maxDist;
155 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());
156 for(int ir = 0;ir<nRecJets;++ir){
157 Double_t dR = genJets[ig].DeltaR(&recJets[ir]);
158 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());
159 if(iDebug>1)Printf("Distance (%d)--(%d) %3.3f ",ig,ir,dR);
165 if(iRecIndex[ig]>=0)iFlag[ig*nGenJets+iRecIndex[ig]]+=1;
170 for(int ir = 0;ir<nRecJets;++ir){
171 Float_t dist = maxDist;
172 for(int ig = 0;ig<nGenJets;++ig){
173 Double_t dR = genJets[ig].DeltaR(&recJets[ir]);
179 if(iGenIndex[ir]>=0)iFlag[iGenIndex[ir]*nGenJets+ir]+=2;
184 // check for "true" correlations
186 if(iDebug>1)Printf(">>>>>> Matrix");
188 for(int ig = 0;ig<nGenJets;++ig){
189 for(int ir = 0;ir<nRecJets;++ir){
191 if(iDebug>1)printf("Flag[%d][%d] %d ",ig,ir,iFlag[ig*nGenJets+ir]);
194 // we have a uniqie correlation
195 if(iFlag[ig*nGenJets+ir]==3){
201 // we just take the correlation from on side
202 if((iFlag[ig*nGenJets+ir]&2)==2){
205 if((iFlag[ig*nGenJets+ir]&1)==1){
210 if(iDebug>1)printf("\n");
216 void AliAnalysisHelperJetTasks::MergeOutput(char* cFiles, char* cList){
218 // This is used to merge the analysis-output from different
219 // data samples/pt_hard bins
220 // in case the eventweigth was set to xsection/ntrials already, this
221 // is not needed. Both methods only work in case we do not mix different
222 // pt_hard bins, and do not have overlapping bins
224 const Int_t nMaxBins = 12;
225 // LHC08q jetjet100: Mean = 1.42483e-03, RMS = 6.642e-05
226 // LHC08r jetjet50: Mean = 2.44068e-02, RMS = 1.144e-03
227 // LHC08v jetjet15-50: Mean = 2.168291 , RMS = 7.119e-02
228 // const Float_t xsection[nBins] = {2.168291,2.44068e-02};
230 Float_t xsection[nMaxBins];
231 Float_t nTrials[nMaxBins];
232 Float_t sf[nMaxBins];
233 TList *lIn[nMaxBins];
234 TFile *fIn[nMaxBins];
242 fIn[ibTotal] = TFile::Open(cFile);
243 lIn[ibTotal] = (TList*)fIn[ibTotal]->Get(cList);
244 Printf("Merging file %s",cFile);
246 Printf("%s:%d No list %s found, exiting...",__FILE__,__LINE__,cList);
250 TH1* hTrials = (TH1F*)lIn[ibTotal]->FindObject("fh1Trials");
252 Printf("%s:%d fh1PtHard_Trials not found in list, exiting...",__FILE__,__LINE__);
255 TProfile* hXsec = (TProfile*)lIn[ibTotal]->FindObject("fh1Xsec");
257 Printf("%s:%d fh1Xsec not found in list, exiting...",__FILE__,__LINE__);
260 xsection[ibTotal] = hXsec->GetBinContent(1);
261 nTrials[ibTotal] = hTrials->Integral();
262 sf[ibTotal] = xsection[ibTotal]/ nTrials[ibTotal];
267 Printf("%s:%d No files found for mergin, exiting",__FILE__,__LINE__);
271 TFile *fOut = new TFile("allpt.root","RECREATE");
272 TList *lOut = new TList();
273 lOut->SetName(lIn[0]->GetName());
274 // for the start scale all...
275 for(int ie = 0; ie < lIn[0]->GetEntries();++ie){
277 THnSparse *hnAdd = 0;
278 for(int ib = 0;ib < ibTotal;++ib){
279 // dynamic cast does not work with cint
280 TObject *h = lIn[ib]->At(ie);
281 if(h->InheritsFrom("TH1")){
284 h1Add = (TH1*)h1->Clone(h1->GetName());
285 h1Add->Scale(sf[ib]);
288 h1Add->Add(h1,sf[ib]);
291 else if(h->InheritsFrom("THnSparse")){
292 THnSparse *hn = (THnSparse*)h;
294 hnAdd = (THnSparse*)hn->Clone(hn->GetName());
295 hnAdd->Scale(sf[ib]);
298 hnAdd->Add(hn,sf[ib]);
304 if(h1Add)lOut->Add(h1Add);
305 else if(hnAdd)lOut->Add(hnAdd);
308 lOut->Write(lOut->GetName(),TObject::kSingleKey);
312 Bool_t AliAnalysisHelperJetTasks::PythiaInfoFromFile(const char* currFile,Float_t &fXsec,Float_t &fTrials){
314 // get the cross section and the trails either from pyxsec.root or from pysec_hists.root
315 // This is to called in Notify and should provide the path to the AOD/ESD file
317 TString file(currFile);
321 if(file.Contains("root_archive.zip#")){
322 Ssiz_t pos1 = file.Index("root_archive",12,TString::kExact);
323 Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
324 file.Replace(pos+1,20,"");
327 // not an archive take the basename....
328 file.ReplaceAll(gSystem->BaseName(file.Data()),"");
330 Printf("%s",file.Data());
335 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
337 // next trial fetch the histgram file
338 fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
340 // not a severe condition but inciate that we have no information
344 // find the tlist we want to be independtent of the name so use the Tkey
345 TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0);
350 TList *list = dynamic_cast<TList*>(key->ReadObj());
355 fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
356 fTrials = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
359 } // no tree pyxsec.root
361 TTree *xtree = (TTree*)fxsec->Get("Xsection");
367 Double_t xsection = 0;
368 xtree->SetBranchAddress("xsection",&xsection);
369 xtree->SetBranchAddress("ntrials",&ntrials);
378 Bool_t AliAnalysisHelperJetTasks::Selected(Bool_t bSet,Bool_t bNew){
379 static Bool_t bSelected = kTRUE; // if service task is not run we acccpet all
386 //___________________________________________________________________________________________________________
388 Bool_t AliAnalysisHelperJetTasks::GetEventShapes(TVector3 &n01, TVector3 * pTrack, Int_t nTracks, Double_t * eventShapes)
391 // Event shape calculation
392 // sona.pochybova@cern.ch
394 const Int_t kTracks = 1000;
395 if(nTracks>kTracks)return kFALSE;
397 //variables for thrust calculation
398 TVector3 pTrackPerp[kTracks];
406 Double_t psum102 = 0;
407 Double_t psum103 = 0;
409 Double_t thrust[kTracks];
411 Double_t thrust02[kTracks];
413 Double_t thrust03[kTracks];
416 //Sphericity calculation variables
435 //loop for thrust calculation
438 for(Int_t i = 0; i < nTracks; i++)
440 pTrackPerp[i].SetXYZ(pTrack[i].X(), pTrack[i].Y(), 0);
441 psum2 += pTrackPerp[i].Mag();
444 //additional starting axis
446 n02 = pTrack[1].Unit();
449 n03 = pTrack[2].Unit();
452 //switches for calculating thrust for different starting points
457 //indexes for iteration of different starting points
462 //maximal number of iterations
463 // Int_t nMaxIter = 100;
465 for(Int_t k = 0; k < nTracks; k++)
469 psum.SetXYZ(0., 0., 0.);
471 for(Int_t i = 0; i < nTracks; i++)
473 psum1 += (TMath::Abs(n01.Dot(pTrackPerp[i])));
474 if (n01.Dot(pTrackPerp[i]) > 0) psum += pTrackPerp[i];
475 if (n01.Dot(pTrackPerp[i]) < 0) psum -= pTrackPerp[i];
477 thrust[l1] = psum1/psum2;
481 psum02.SetXYZ(0., 0., 0.);
483 for(Int_t i = 0; i < nTracks; i++)
485 psum102 += (TMath::Abs(n02.Dot(pTrackPerp[i])));
486 if (n02.Dot(pTrackPerp[i]) > 0) psum02 += pTrackPerp[i];
487 if (n02.Dot(pTrackPerp[i]) < 0) psum02 -= pTrackPerp[i];
489 thrust02[l2] = psum102/psum2;
493 psum03.SetXYZ(0., 0., 0.);
495 for(Int_t i = 0; i < nTracks; i++)
497 psum103 += (TMath::Abs(n03.Dot(pTrackPerp[i])));
498 if (n03.Dot(pTrackPerp[i]) > 0) psum03 += pTrackPerp[i];
499 if (n03.Dot(pTrackPerp[i]) < 0) psum03 -= pTrackPerp[i];
501 thrust03[l3] = psum103/psum2;
504 //check whether thrust value converged
505 if(TMath::Abs(th-thrust[l1]) < 10e-7){
509 if(TMath::Abs(th02-thrust02[l2]) < 10e-7){
513 if(TMath::Abs(th03-thrust03[l3]) < 10e-7){
517 //if it didn't, continue with the calculation
536 //if thrust values for all starting direction converged check if to the same value
537 if(switch2 == 0 && switch1 == 0 && switch3 == 0){
538 if(TMath::Abs(th-th02) < 10e-7 && TMath::Abs(th-th03) < 10e-7 && TMath::Abs(th02-th03) < 10e-7){
540 AliInfoGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),Form("===== THRUST VALUE FOUND AT %d :: %f\n", k, th));
543 //if they did not, reset switches
554 // Printf("========== %d +++ th :: %f=============\n", l1, th);
555 // Printf("========== %d +++ th2 :: %f=============\n", l2, th02);
556 // Printf("========== %d +++ th3 :: %f=============\n", l3, th03);
560 //if no common limitng value was found, take the maximum and take the corresponding thrust axis
561 if(switch1 == 1 && switch2 == 1 && switch3 == 1){
562 eventShapes[0] = TMath::Max(thrust[l1-1], thrust02[l2-1]);
563 eventShapes[0] = TMath::Max(eventShapes[0], thrust03[l3-1]);
564 if(TMath::Abs(eventShapes[0]-thrust[l1-1]) < 10e-7)
566 if(TMath::Abs(eventShapes[0]-thrust02[l2-1]) < 10e-7)
568 if(TMath::Abs(eventShapes[0]-thrust03[l3-1]) < 10e-7)
570 Printf("NO LIMITING VALUE FOUND :: MAXIMUM = %f\n", eventShapes[0]);
574 //other event shapes variables
576 for(Int_t j = 0; j < nTracks; j++)
578 s00 = s00 + (pTrack[j].Px()*pTrack[j].Px())/pTrack[j].Mag();
579 s01 = s01 + (pTrack[j].Px()*pTrack[j].Py())/pTrack[j].Mag();
580 s02 = s02 + (pTrack[j].Px()*pTrack[j].Pz())/pTrack[j].Mag();
582 s10 = s10 + (pTrack[j].Py()*pTrack[j].Px())/pTrack[j].Mag();
583 s11 = s11 + (pTrack[j].Py()*pTrack[j].Py())/pTrack[j].Mag();
584 s12 = s12 + (pTrack[j].Py()*pTrack[j].Pz())/pTrack[j].Mag();
586 s20 = s20 + (pTrack[j].Pz()*pTrack[j].Px())/pTrack[j].Mag();
587 s21 = s21 + (pTrack[j].Pz()*pTrack[j].Py())/pTrack[j].Mag();
588 s22 = s22 + (pTrack[j].Pz()*pTrack[j].Pz())/pTrack[j].Mag();
590 ptot += pTrack[j].Mag();
607 TMatrixDSymEigen eigen(m);
608 TVectorD eigenVal = eigen.GetEigenValues();
610 Double_t sphericity = (3/2)*(eigenVal(2)+eigenVal(1));
611 eventShapes[1] = sphericity;
613 Double_t aplanarity = (3/2)*(eigenVal(2));
614 eventShapes[2] = aplanarity;
616 c = 3*(eigenVal(0)*eigenVal(1)+eigenVal(0)*eigenVal(2)+eigenVal(1)*eigenVal(2));
624 //__________________________________________________________________________________________________________________________
625 // Trigger Decisions copid from PWG0/AliTriggerAnalysis
628 Bool_t AliAnalysisHelperJetTasks::IsTriggerFired(const AliVEvent* aEv, Trigger trigger)
630 // checks if an event has been triggered
631 // no usage of ofline trigger here yet
632 return IsTriggerBitFired(aEv, trigger);
635 Bool_t AliAnalysisHelperJetTasks::IsTriggerBitFired(const AliVEvent* aEv, Trigger trigger)
637 // checks if an event is fired using the trigger bits
639 return IsTriggerBitFired(aEv->GetTriggerMask(), trigger);
642 Bool_t AliAnalysisHelperJetTasks::IsTriggerBitFired(ULong64_t triggerMask, Trigger trigger)
644 // checks if an event is fired using the trigger bits
646 // this function needs the branch TriggerMask in the ESD
648 // definitions from p-p.cfg
649 ULong64_t spdFO = (1 << 14);
650 ULong64_t v0left = (1 << 10);
651 ULong64_t v0right = (1 << 11);
662 if (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)))
668 if (triggerMask & spdFO && ((triggerMask & v0left) || (triggerMask & v0right)))
674 if (triggerMask & spdFO && (triggerMask & v0left) && (triggerMask & v0right))
680 if (triggerMask & spdFO)
685 Printf("IsEventTriggered: ERROR: Trigger type %d not implemented in this method", (Int_t) trigger);
692 Bool_t AliAnalysisHelperJetTasks::IsTriggerBitFired(const AliVEvent* aEv, ULong64_t tclass)
694 // Checks if corresponding bit in mask is on
696 ULong64_t trigmask = aEv->GetTriggerMask();
697 return (trigmask & (1ull << (tclass-1)));