8 #include "AliMCEvent.h"
11 #include "AliGenEventHeader.h"
12 #include "AliGenCocktailEventHeader.h"
13 #include "AliGenPythiaEventHeader.h"
16 #include "AliAnalysisHelperJetTasks.h"
19 ClassImp(AliAnalysisHelperJetTasks)
24 AliGenPythiaEventHeader* AliAnalysisHelperJetTasks::GetPythiaEventHeader(AliMCEvent *mcEvent){
26 AliGenEventHeader* genHeader = mcEvent->GenEventHeader();
27 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(genHeader);
30 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(genHeader);
32 if (!genCocktailHeader) {
33 Printf("%s %d: Unknown header type (not Pythia or Cocktail)",(char*)__FILE__,__LINE__);
36 TList* headerList = genCocktailHeader->GetHeaders();
37 for (Int_t i=0; i<headerList->GetEntries(); i++) {
38 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
43 Printf("%s %d: PythiaHeader not found!",(char*)__FILE__,__LINE__);
47 return pythiaGenHeader;
52 void AliAnalysisHelperJetTasks::PrintStack(AliMCEvent *mcEvent,Int_t iFirst,Int_t iLast,Int_t iMaxPrint){
54 AliStack *stack = mcEvent->Stack();
56 Printf("%s%d No Stack available",(char*)__FILE__,__LINE__);
60 static Int_t iCount = 0;
61 if(iCount>iMaxPrint)return;
62 Int_t nStack = stack->GetNtrack();
63 if(iLast == 0)iLast = nStack;
64 else if(iLast > nStack)iLast = nStack;
67 Printf("####################################################################");
68 for(Int_t np = iFirst;np<iLast;++np){
69 TParticle *p = stack->Particle(np);
70 Printf("Nr.%d --- Status %d ---- Mother1 %d Mother2 %d Daughter1 %d Daughter2 %d ",
71 np,p->GetStatusCode(),p->GetMother(0),p->GetMother(1),p->GetDaughter(0),p->GetDaughter(1));
72 Printf("Eta %3.3f Phi %3.3f ",p->Eta(),p->Phi());
74 Printf("---------------------------------------");
82 void AliAnalysisHelperJetTasks::GetClosestJets(AliAODJet *genJets,const Int_t &kGenJets,
83 AliAODJet *recJets,const Int_t &kRecJets,
84 Int_t *iGenIndex,Int_t *iRecIndex,
85 Int_t iDebug,Float_t maxDist){
88 // Relate the two input jet Arrays
92 // The association has to be unique
93 // So check in two directions
94 // find the closest rec to a gen
95 // and check if there is no other rec which is closer
96 // Caveat: Close low energy/split jets may disturb this correlation
99 // Idea: search in two directions generated e.g (a--e) and rec (1--3)
100 // Fill a matrix with Flags (1 for closest rec jet, 2 for closest rec jet
101 // in the end we have something like this
115 // Only entries with "3" match from both sides
117 // In case we have more jets than kmaxjets only the
118 // first kmaxjets are searched
120 // use kMaxJets for a test not to fragemnt the memory...
122 for(int i = 0;i < kGenJets;++i)iGenIndex[i] = -1;
123 for(int j = 0;j < kRecJets;++j)iRecIndex[j] = -1;
129 const Int_t nGenJets = TMath::Min(kMaxJets,kGenJets);
130 const Int_t nRecJets = TMath::Min(kMaxJets,kRecJets);
132 if(nRecJets==0||nGenJets==0)return;
134 // UShort_t *iFlag = new UShort_t[nGenJets*nRecJets];
135 UShort_t iFlag[kMaxJets*kMaxJets];
136 for(int i = 0;i < nGenJets;++i){
137 for(int j = 0;j < nRecJets;++j){
138 iFlag[i*nGenJets+j] = 0;
144 // find the closest distance to the generated
145 for(int ig = 0;ig<nGenJets;++ig){
146 Float_t dist = maxDist;
147 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());
148 for(int ir = 0;ir<nRecJets;++ir){
149 Double_t dR = genJets[ig].DeltaR(&recJets[ir]);
150 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());
151 if(iDebug>1)Printf("Distance (%d)--(%d) %3.3f ",ig,ir,dR);
157 if(iRecIndex[ig]>=0)iFlag[ig*nGenJets+iRecIndex[ig]]+=1;
162 for(int ir = 0;ir<nRecJets;++ir){
163 Float_t dist = maxDist;
164 for(int ig = 0;ig<nGenJets;++ig){
165 Double_t dR = genJets[ig].DeltaR(&recJets[ir]);
171 if(iGenIndex[ir]>=0)iFlag[iGenIndex[ir]*nGenJets+ir]+=2;
176 // check for "true" correlations
178 if(iDebug>1)Printf(">>>>>> Matrix");
180 for(int ig = 0;ig<nGenJets;++ig){
181 for(int ir = 0;ir<nRecJets;++ir){
183 if(iDebug>1)printf("Flag[%d][%d] %d ",ig,ir,iFlag[ig*nGenJets+ir]);
186 // we have a uniqie correlation
187 if(iFlag[ig*nGenJets+ir]==3){
193 // we just take the correlation from on side
194 if((iFlag[ig*nGenJets+ir]&2)==2){
197 if((iFlag[ig*nGenJets+ir]&1)==1){
202 if(iDebug>1)printf("\n");
208 void AliAnalysisHelperJetTasks::MergeOutput(char* cFiles, char* cList){
210 // This is used to merge the analysis-output from different
211 // data samples/pt_hard bins
212 // in case the eventweigth was set to xsection/ntrials already, this
213 // is not needed. Both methods only work in case we do not mix different
214 // pt_hard bins, and do not have overlapping bins
216 const Int_t nMaxBins = 12;
217 // LHC08q jetjet100: Mean = 1.42483e-03, RMS = 6.642e-05
218 // LHC08r jetjet50: Mean = 2.44068e-02, RMS = 1.144e-03
219 // LHC08v jetjet15-50: Mean = 2.168291 , RMS = 7.119e-02
220 // const Float_t xsection[nBins] = {2.168291,2.44068e-02};
222 Float_t xsection[nMaxBins];
223 Float_t nTrials[nMaxBins];
224 Float_t sf[nMaxBins];
225 TList *lIn[nMaxBins];
226 TFile *fIn[nMaxBins];
234 fIn[ibTotal] = TFile::Open(cFile);
235 lIn[ibTotal] = (TList*)fIn[ibTotal]->Get(cList);
237 Printf("%s:%d No list %s found, exiting...",__FILE__,__LINE__,cList);
241 TH1* hTrials = (TH1F*)lIn[ibTotal]->FindObject("fh1Trials");
243 Printf("%s:%d fh1PtHard_Trials not found in list, exiting...",__FILE__,__LINE__);
246 TProfile* hXsec = (TProfile*)lIn[ibTotal]->FindObject("fh1Xsec");
248 Printf("%s:%d fh1Xsec not found in list, exiting...",__FILE__,__LINE__);
251 xsection[ibTotal] = hXsec->GetBinContent(1);
252 nTrials[ibTotal] = hTrials->Integral();
253 sf[ibTotal] = xsection[ibTotal]/ nTrials[ibTotal];
258 Printf("%s:%d No files found for mergin, exiting",__FILE__,__LINE__);
262 TFile *fOut = new TFile("allpt.root","RECREATE");
263 TList *lOut = new TList();
264 lOut->SetName(lIn[0]->GetName());
265 // for the start scale all...
266 for(int ie = 0; ie < lIn[0]->GetEntries();++ie){
268 THnSparse *hnAdd = 0;
269 for(int ib = 0;ib < ibTotal;++ib){
270 // dynamic cast does not work with cint
271 TObject *h = lIn[ib]->At(ie);
272 if(h->InheritsFrom("TH1")){
275 h1Add = (TH1*)h1->Clone(h1->GetName());
276 h1Add->Scale(sf[ib]);
279 h1Add->Add(h1,sf[ib]);
282 else if(h->InheritsFrom("THnSparse")){
283 THnSparse *hn = (THnSparse*)h;
285 hnAdd = (THnSparse*)hn->Clone(hn->GetName());
286 hnAdd->Scale(sf[ib]);
289 hnAdd->Add(hn,sf[ib]);
295 if(h1Add)lOut->Add(h1Add);
296 else if(hnAdd)lOut->Add(hnAdd);
299 lOut->Write(lOut->GetName(),TObject::kSingleKey);