fixed directory booking, allow to update files in merging
[u/mrichter/AliRoot.git] / PWG4 / JetTasks / AliAnalysisHelperJetTasks.cxx
CommitLineData
f3050824 1
2#include "TROOT.h"
383d44fd 3#include "TDirectory.h"
519378fb 4#include "TKey.h"
f3050824 5#include "TList.h"
519378fb 6#include "TSystem.h"
188a1ba9 7#include "TH1F.h"
8#include "TProfile.h"
9#include "THnSparse.h"
c6049d04 10#include "TSeqCollection.h"
11#include "TMethodCall.h"
188a1ba9 12#include "TFile.h"
519378fb 13#include "TString.h"
f3050824 14#include "AliMCEvent.h"
5c047edc 15#include "AliLog.h"
59543510 16#include "AliESDEvent.h"
db6bcb0e 17#include "AliAODJet.h"
cce8b687 18#include "AliAODEvent.h"
f3050824 19#include "AliStack.h"
20#include "AliGenEventHeader.h"
21#include "AliGenCocktailEventHeader.h"
955d29ba 22#include <AliGenDPMjetEventHeader.h>
f3050824 23#include "AliGenPythiaEventHeader.h"
24#include <fstream>
25#include <iostream>
26#include "AliAnalysisHelperJetTasks.h"
6f3f79de 27#include "TMatrixDSym.h"
28#include "TMatrixDSymEigen.h"
29#include "TVector.h"
f3050824 30
31ClassImp(AliAnalysisHelperJetTasks)
32
955d29ba 33Int_t AliAnalysisHelperJetTasks::fgLastProcessType = -1;
f3050824 34
35
36AliGenPythiaEventHeader* AliAnalysisHelperJetTasks::GetPythiaEventHeader(AliMCEvent *mcEvent){
37
3e1c1eee 38 if(!mcEvent)return 0;
f3050824 39 AliGenEventHeader* genHeader = mcEvent->GenEventHeader();
40 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(genHeader);
41 if(!pythiaGenHeader){
42 // cocktail ??
43 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(genHeader);
44
45 if (!genCocktailHeader) {
5c047edc 46 AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Unknown header type (not Pythia or Cocktail)");
47 // AliWarning(Form("%s %d: Unknown header type (not Pythia or Cocktail)",(char*)__FILE__,__LINE__));
f3050824 48 return 0;
49 }
50 TList* headerList = genCocktailHeader->GetHeaders();
51 for (Int_t i=0; i<headerList->GetEntries(); i++) {
52 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
53 if (pythiaGenHeader)
54 break;
55 }
56 if(!pythiaGenHeader){
5c047edc 57 AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Pythia event header not found");
f3050824 58 return 0;
59 }
60 }
61 return pythiaGenHeader;
62
63}
64
65
66void AliAnalysisHelperJetTasks::PrintStack(AliMCEvent *mcEvent,Int_t iFirst,Int_t iLast,Int_t iMaxPrint){
67
68 AliStack *stack = mcEvent->Stack();
69 if(!stack){
70 Printf("%s%d No Stack available",(char*)__FILE__,__LINE__);
71 return;
72 }
73
74 static Int_t iCount = 0;
75 if(iCount>iMaxPrint)return;
76 Int_t nStack = stack->GetNtrack();
77 if(iLast == 0)iLast = nStack;
78 else if(iLast > nStack)iLast = nStack;
79
80
81 Printf("####################################################################");
82 for(Int_t np = iFirst;np<iLast;++np){
83 TParticle *p = stack->Particle(np);
84 Printf("Nr.%d --- Status %d ---- Mother1 %d Mother2 %d Daughter1 %d Daughter2 %d ",
85 np,p->GetStatusCode(),p->GetMother(0),p->GetMother(1),p->GetDaughter(0),p->GetDaughter(1));
86 Printf("Eta %3.3f Phi %3.3f ",p->Eta(),p->Phi());
87 p->Print();
88 Printf("---------------------------------------");
89 }
90 iCount++;
91}
92
93
db6bcb0e 94
95
3dc5a1a4 96void AliAnalysisHelperJetTasks::GetClosestJets(AliAODJet *genJets,const Int_t &kGenJets,
97 AliAODJet *recJets,const Int_t &kRecJets,
db6bcb0e 98 Int_t *iGenIndex,Int_t *iRecIndex,
99 Int_t iDebug,Float_t maxDist){
100
101 //
102 // Relate the two input jet Arrays
103 //
104
105 //
106 // The association has to be unique
107 // So check in two directions
108 // find the closest rec to a gen
109 // and check if there is no other rec which is closer
110 // Caveat: Close low energy/split jets may disturb this correlation
111
3dc5a1a4 112
db6bcb0e 113 // Idea: search in two directions generated e.g (a--e) and rec (1--3)
114 // Fill a matrix with Flags (1 for closest rec jet, 2 for closest rec jet
115 // in the end we have something like this
116 // 1 2 3
117 // ------------
118 // a| 3 2 0
119 // b| 0 1 0
120 // c| 0 0 3
121 // d| 0 0 1
122 // e| 0 0 1
123 // Topology
124 // 1 2
125 // a b
126 //
127 // d c
128 // 3 e
129 // Only entries with "3" match from both sides
3dc5a1a4 130
131 // In case we have more jets than kmaxjets only the
132 // first kmaxjets are searched
133 // all other are -1
134 // use kMaxJets for a test not to fragemnt the memory...
135
136 for(int i = 0;i < kGenJets;++i)iGenIndex[i] = -1;
137 for(int j = 0;j < kRecJets;++j)iRecIndex[j] = -1;
138
139
db6bcb0e 140
141 const int kMode = 3;
142
3dc5a1a4 143 const Int_t nGenJets = TMath::Min(kMaxJets,kGenJets);
144 const Int_t nRecJets = TMath::Min(kMaxJets,kRecJets);
db6bcb0e 145
146 if(nRecJets==0||nGenJets==0)return;
147
3dc5a1a4 148 // UShort_t *iFlag = new UShort_t[nGenJets*nRecJets];
149 UShort_t iFlag[kMaxJets*kMaxJets];
db6bcb0e 150 for(int i = 0;i < nGenJets;++i){
151 for(int j = 0;j < nRecJets;++j){
152 iFlag[i*nGenJets+j] = 0;
153 }
154 }
155
156
157
158 // find the closest distance to the generated
159 for(int ig = 0;ig<nGenJets;++ig){
160 Float_t dist = maxDist;
161 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());
162 for(int ir = 0;ir<nRecJets;++ir){
163 Double_t dR = genJets[ig].DeltaR(&recJets[ir]);
164 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());
165 if(iDebug>1)Printf("Distance (%d)--(%d) %3.3f ",ig,ir,dR);
166 if(dR<dist){
167 iRecIndex[ig] = ir;
168 dist = dR;
169 }
170 }
171 if(iRecIndex[ig]>=0)iFlag[ig*nGenJets+iRecIndex[ig]]+=1;
172 // reset...
173 iRecIndex[ig] = -1;
174 }
175 // other way around
176 for(int ir = 0;ir<nRecJets;++ir){
177 Float_t dist = maxDist;
178 for(int ig = 0;ig<nGenJets;++ig){
179 Double_t dR = genJets[ig].DeltaR(&recJets[ir]);
180 if(dR<dist){
181 iGenIndex[ir] = ig;
182 dist = dR;
183 }
184 }
185 if(iGenIndex[ir]>=0)iFlag[iGenIndex[ir]*nGenJets+ir]+=2;
186 // reset...
187 iGenIndex[ir] = -1;
188 }
189
190 // check for "true" correlations
191
192 if(iDebug>1)Printf(">>>>>> Matrix");
193
194 for(int ig = 0;ig<nGenJets;++ig){
195 for(int ir = 0;ir<nRecJets;++ir){
196 // Print
197 if(iDebug>1)printf("Flag[%d][%d] %d ",ig,ir,iFlag[ig*nGenJets+ir]);
198
199 if(kMode==3){
200 // we have a uniqie correlation
201 if(iFlag[ig*nGenJets+ir]==3){
202 iGenIndex[ir] = ig;
203 iRecIndex[ig] = ir;
204 }
205 }
206 else{
207 // we just take the correlation from on side
208 if((iFlag[ig*nGenJets+ir]&2)==2){
209 iGenIndex[ir] = ig;
210 }
211 if((iFlag[ig*nGenJets+ir]&1)==1){
212 iRecIndex[ig] = ir;
213 }
214 }
215 }
216 if(iDebug>1)printf("\n");
217 }
db6bcb0e 218}
219
220
57cd3e7c 221void AliAnalysisHelperJetTasks::MergeOutputDirs(const char* cFiles,const char* cPattern,const char *cOutFile,Bool_t bUpdate){
c6049d04 222 // Routine to merge only directories containing the pattern
223 //
224 TString outFile(cOutFile);
225 if(outFile.Length()==0)outFile = Form("%s.root",cPattern);
226 ifstream in1;
227 in1.open(cFiles);
228 // open all files
229 TList fileList;
230 char cFile[240];
57cd3e7c 231 while(in1>>cFile){// only open the first file
232 Printf("Adding %s",cFile);
233 TFile *f1 = TFile::Open(cFile);
234 fileList.Add(f1);
c6049d04 235 }
236
237 TFile *fOut = 0;
238 if(fileList.GetEntries()){// open the first file
239 TFile* fIn = dynamic_cast<TFile*>(fileList.At(0));
57cd3e7c 240 if(!fIn){
c6049d04 241 Printf("Input File not Found");
242 }
243 // fetch the keys for the directories
244 TList *ldKeys = fIn->GetListOfKeys();
245 for(int id = 0;id < ldKeys->GetEntries();id++){
246 // check if it is a directory
247 TKey *dKey = (TKey*)ldKeys->At(id);
248 TDirectory *dir = dynamic_cast<TDirectory*>(dKey->ReadObj());
249 if(dir){
250 TString dName(dir->GetName());
251 if(dName.Contains(cPattern)){
252 // open new file if first match
253 if(!fOut){
57cd3e7c 254 if(bUpdate)fOut = new TFile(outFile.Data(),"UPDATE");
255 else fOut = new TFile(outFile.Data(),"RECREATE");
c6049d04 256 }
257 // merge all the stuff that is in this directory
258 TList *llKeys = dir->GetListOfKeys();
259 TList *tmplist;
260 TMethodCall callEnv;
57cd3e7c 261
262 fOut->cd();
263 TDirectory *dOut = fOut->mkdir(dir->GetName());
264
c6049d04 265 for(int il = 0;il < llKeys->GetEntries();il++){
57cd3e7c 266 TKey *lKey = (TKey*)llKeys->At(il);
c6049d04 267 TObject *object = dynamic_cast<TObject*>(lKey->ReadObj());
268 // from TSeqCollections::Merge
269 if(!object)continue;
270 // If current object is not mergeable just skip it
271 if (!object->IsA()) {
272 continue;
273 }
274 callEnv.InitWithPrototype(object->IsA(), "Merge", "TCollection*");
275 if (!callEnv.IsValid()) {
276 continue;
277 }
278 // Current object mergeable - get corresponding objects in input lists
279 tmplist = new TList();
280 for(int i = 1; i < fileList.GetEntries();i++){
281 TDirectory *fInTmp = dynamic_cast<TDirectory*>(fileList.At(i));
282 if(!fInTmp){
283 Printf("File %d not found",i);
284 continue;
285 }
286 TDirectory *dTmp = (TDirectory*)fInTmp->Get(dName.Data());
287 if(!dTmp){
288 Printf("Directory %s not found",dName.Data());
289 continue;
290 }
291 TObject* oTmp = (TObject*)dTmp->Get(object->GetName());
292 if(!oTmp){
293 Printf("Object %s not found",object->GetName());
294 continue;
295 }
296 tmplist->Add(oTmp);
297 }
298 callEnv.SetParam((Long_t) tmplist);
299 callEnv.Execute(object);
300 delete tmplist;tmplist = 0;
57cd3e7c 301 dOut->cd();
302 object->Write(object->GetName(),TObject::kSingleKey);
c6049d04 303 }
304 }
305 }
306 }
307 if(fOut){
308 fOut->Close();
309 }
310 }
311}
db6bcb0e 312
383d44fd 313void AliAnalysisHelperJetTasks::MergeOutput(char* cFiles, char* cDir, char *cList,char *cOutFile,Bool_t bUpdate){
db6bcb0e 314
188a1ba9 315 // This is used to merge the analysis-output from different
316 // data samples/pt_hard bins
317 // in case the eventweigth was set to xsection/ntrials already, this
318 // is not needed. Both methods only work in case we do not mix different
319 // pt_hard bins, and do not have overlapping bins
db6bcb0e 320
188a1ba9 321 const Int_t nMaxBins = 12;
322 // LHC08q jetjet100: Mean = 1.42483e-03, RMS = 6.642e-05
323 // LHC08r jetjet50: Mean = 2.44068e-02, RMS = 1.144e-03
324 // LHC08v jetjet15-50: Mean = 2.168291 , RMS = 7.119e-02
325 // const Float_t xsection[nBins] = {2.168291,2.44068e-02};
326
327 Float_t xsection[nMaxBins];
328 Float_t nTrials[nMaxBins];
329 Float_t sf[nMaxBins];
330 TList *lIn[nMaxBins];
383d44fd 331 TDirectory *dIn[nMaxBins];
188a1ba9 332 TFile *fIn[nMaxBins];
333
334 ifstream in1;
335 in1.open(cFiles);
336
337 char cFile[120];
338 Int_t ibTotal = 0;
339 while(in1>>cFile){
340 fIn[ibTotal] = TFile::Open(cFile);
4d723ede 341 if(strlen(cDir)==0){
342 dIn[ibTotal] = gDirectory;
343 }
344 else{
345 dIn[ibTotal] = (TDirectory*)fIn[ibTotal]->Get(cDir);
346 }
383d44fd 347 if(!dIn[ibTotal]){
348 Printf("%s:%d No directory %s found, exiting...",__FILE__,__LINE__,cDir);
349 fIn[ibTotal]->ls();
350 return;
351 }
352
353 lIn[ibTotal] = (TList*)dIn[ibTotal]->Get(cList);
354 Printf("Merging file %s %s",cFile, cDir);
188a1ba9 355 if(!lIn[ibTotal]){
356 Printf("%s:%d No list %s found, exiting...",__FILE__,__LINE__,cList);
357 fIn[ibTotal]->ls();
358 return;
359 }
360 TH1* hTrials = (TH1F*)lIn[ibTotal]->FindObject("fh1Trials");
361 if(!hTrials){
362 Printf("%s:%d fh1PtHard_Trials not found in list, exiting...",__FILE__,__LINE__);
363 return;
364 }
365 TProfile* hXsec = (TProfile*)lIn[ibTotal]->FindObject("fh1Xsec");
366 if(!hXsec){
367 Printf("%s:%d fh1Xsec not found in list, exiting...",__FILE__,__LINE__);
368 return;
369 }
370 xsection[ibTotal] = hXsec->GetBinContent(1);
371 nTrials[ibTotal] = hTrials->Integral();
372 sf[ibTotal] = xsection[ibTotal]/ nTrials[ibTotal];
373 ibTotal++;
374 }
375
376 if(ibTotal==0){
377 Printf("%s:%d No files found for mergin, exiting",__FILE__,__LINE__);
378 return;
379 }
380
383d44fd 381 TFile *fOut = 0;
382 if(bUpdate)fOut = new TFile(cOutFile,"UPDATE");
383 else fOut = new TFile(cOutFile,"RECREATE");
384 TDirectory *dOut = fOut->mkdir(dIn[0]->GetName());
385 dOut->cd();
188a1ba9 386 TList *lOut = new TList();
387 lOut->SetName(lIn[0]->GetName());
383d44fd 388
188a1ba9 389 // for the start scale all...
390 for(int ie = 0; ie < lIn[0]->GetEntries();++ie){
391 TH1 *h1Add = 0;
392 THnSparse *hnAdd = 0;
393 for(int ib = 0;ib < ibTotal;++ib){
394 // dynamic cast does not work with cint
395 TObject *h = lIn[ib]->At(ie);
396 if(h->InheritsFrom("TH1")){
397 TH1 *h1 = (TH1*)h;
398 if(ib==0){
399 h1Add = (TH1*)h1->Clone(h1->GetName());
400 h1Add->Scale(sf[ib]);
401 }
402 else{
403 h1Add->Add(h1,sf[ib]);
404 }
405 }
406 else if(h->InheritsFrom("THnSparse")){
407 THnSparse *hn = (THnSparse*)h;
408 if(ib==0){
409 hnAdd = (THnSparse*)hn->Clone(hn->GetName());
410 hnAdd->Scale(sf[ib]);
411 }
412 else{
413 hnAdd->Add(hn,sf[ib]);
414 }
415 }
416
417
418 }// ib
419 if(h1Add)lOut->Add(h1Add);
420 else if(hnAdd)lOut->Add(hnAdd);
421 }
383d44fd 422 dOut->cd();
188a1ba9 423 lOut->Write(lOut->GetName(),TObject::kSingleKey);
424 fOut->Close();
425}
519378fb 426
427Bool_t AliAnalysisHelperJetTasks::PythiaInfoFromFile(const char* currFile,Float_t &fXsec,Float_t &fTrials){
428 //
429 // get the cross section and the trails either from pyxsec.root or from pysec_hists.root
430 // This is to called in Notify and should provide the path to the AOD/ESD file
431
432 TString file(currFile);
433 fXsec = 0;
434 fTrials = 1;
435
436 if(file.Contains("root_archive.zip#")){
437 Ssiz_t pos1 = file.Index("root_archive",12,TString::kExact);
438 Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
439 file.Replace(pos+1,20,"");
440 }
441 else {
442 // not an archive take the basename....
443 file.ReplaceAll(gSystem->BaseName(file.Data()),"");
444 }
445 Printf("%s",file.Data());
446
447
448
449
450 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
451 if(!fxsec){
452 // next trial fetch the histgram file
453 fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
454 if(!fxsec){
455 // not a severe condition but inciate that we have no information
456 return kFALSE;
457 }
458 else{
459 // find the tlist we want to be independtent of the name so use the Tkey
460 TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0);
461 if(!key){
462 fxsec->Close();
463 return kFALSE;
464 }
465 TList *list = dynamic_cast<TList*>(key->ReadObj());
466 if(!list){
467 fxsec->Close();
468 return kFALSE;
469 }
470 fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
471 fTrials = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
472 fxsec->Close();
473 }
474 } // no tree pyxsec.root
475 else {
476 TTree *xtree = (TTree*)fxsec->Get("Xsection");
477 if(!xtree){
478 fxsec->Close();
479 return kFALSE;
480 }
481 UInt_t ntrials = 0;
482 Double_t xsection = 0;
483 xtree->SetBranchAddress("xsection",&xsection);
484 xtree->SetBranchAddress("ntrials",&ntrials);
485 xtree->GetEntry(0);
486 fTrials = ntrials;
487 fXsec = xsection;
488 fxsec->Close();
489 }
490 return kTRUE;
491}
6f3f79de 492
383d44fd 493Bool_t AliAnalysisHelperJetTasks::PrintDirectorySize(const char* currFile){
494
495 TFile *fIn = TFile::Open(currFile);
496 if(!fIn){
497 // not a severe condition but inciate that we have no information
498 return kFALSE;
499 }
500 // find the tlists we want to be independtent of the name so use the Tkey
501 TList* keyList = fIn->GetListOfKeys();
cc89bb69 502 Float_t memorySize = 0;
503 Float_t diskSize = 0;
383d44fd 504
505 for(int i = 0;i < keyList->GetEntries();i++){
506 TKey* ikey = (TKey*)keyList->At(i);
507
508 // TList *list = dynamic_cast<TList*>(key->ReadObj());
509 // TNamed *name = dynamic_cast<TNamed*>(ikey->ReadObj());
510 TDirectory *dir = dynamic_cast<TDirectory*>(ikey->ReadObj());
511
512
cc89bb69 513
514
383d44fd 515 if(dir){
516 Printf("%03d : %60s %8d %8d ",i,dir->GetName(),ikey->GetObjlen(),ikey->GetNbytes());
517 TList * dirKeyList = dir->GetListOfKeys();
518 for(int j = 0;j<dirKeyList->GetEntries();j++){
519 TKey* jkey = (TKey*)dirKeyList->At(j);
520 TList *list = dynamic_cast<TList*>(jkey->ReadObj());
cc89bb69 521
522 memorySize += (Float_t)jkey->GetObjlen()/1024./1024.;
523 diskSize += (Float_t)jkey->GetNbytes()/1024./1024.;
383d44fd 524 if(list){
525 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.);
526 }
527 else{
528 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.);
529 }
530 }
531 }
532 }
cc89bb69 533 Printf("Total %5.2f MB %5.2f MB",memorySize,diskSize);
383d44fd 534 return kTRUE;
535}
536
537
59543510 538Bool_t AliAnalysisHelperJetTasks::Selected(Bool_t bSet,Bool_t bNew){
539 static Bool_t bSelected = kTRUE; // if service task is not run we acccpet all
540 if(bSet){
541 bSelected = bNew;
542 }
543 return bSelected;
544}
545
f2dd0695 546Bool_t AliAnalysisHelperJetTasks::IsCosmic(){
547 return ((SelectInfo()&kIsCosmic)==kIsCosmic);
548}
549
550Bool_t AliAnalysisHelperJetTasks::IsPileUp(){
551 return ((SelectInfo()&kIsPileUp)==kIsPileUp);
552}
553
554
45a11aef 555Bool_t AliAnalysisHelperJetTasks::TestSelectInfo(UInt_t iMask){
556 return ((SelectInfo()&iMask)==iMask);
557}
558
559
f2dd0695 560UInt_t AliAnalysisHelperJetTasks::SelectInfo(Bool_t bSet,UInt_t iNew){
561 static UInt_t iSelectInfo = 0; //
562 if(bSet){
563 iSelectInfo = iNew;
564 }
565 return iSelectInfo;
566}
567
568
6f3f79de 569//___________________________________________________________________________________________________________
570
571Bool_t AliAnalysisHelperJetTasks::GetEventShapes(TVector3 &n01, TVector3 * pTrack, Int_t nTracks, Double_t * eventShapes)
572{
573 // ***
574 // Event shape calculation
575 // sona.pochybova@cern.ch
576
577 const Int_t kTracks = 1000;
578 if(nTracks>kTracks)return kFALSE;
579
20d01a2f 580 //variables for thrust calculation
6f3f79de 581 TVector3 pTrackPerp[kTracks];
6f3f79de 582 Double_t psum2 = 0;
20d01a2f 583
584 TVector3 psum;
585 TVector3 psum02;
586 TVector3 psum03;
587
588 Double_t psum1 = 0;
589 Double_t psum102 = 0;
590 Double_t psum103 = 0;
591
6f3f79de 592 Double_t thrust[kTracks];
593 Double_t th = -3;
20d01a2f 594 Double_t thrust02[kTracks];
595 Double_t th02 = -4;
596 Double_t thrust03[kTracks];
597 Double_t th03 = -5;
6f3f79de 598
20d01a2f 599 //Sphericity calculation variables
6f3f79de 600 TMatrixDSym m(3);
601 Double_t s00 = 0;
602 Double_t s01 = 0;
603 Double_t s02 = 0;
604
605 Double_t s10 = 0;
606 Double_t s11 = 0;
607 Double_t s12 = 0;
608
609 Double_t s20 = 0;
610 Double_t s21 = 0;
611 Double_t s22 = 0;
612
613 Double_t ptot = 0;
614
615 Double_t c = -10;
616
617//
618//loop for thrust calculation
619//
20d01a2f 620
621 for(Int_t i = 0; i < nTracks; i++)
622 {
623 pTrackPerp[i].SetXYZ(pTrack[i].X(), pTrack[i].Y(), 0);
624 psum2 += pTrackPerp[i].Mag();
625 }
626
627 //additional starting axis
628 TVector3 n02;
629 n02 = pTrack[1].Unit();
630 n02.SetZ(0.);
631 TVector3 n03;
632 n03 = pTrack[2].Unit();
633 n03.SetZ(0.);
634
635 //switches for calculating thrust for different starting points
636 Int_t switch1 = 1;
637 Int_t switch2 = 1;
638 Int_t switch3 = 1;
639
640 //indexes for iteration of different starting points
641 Int_t l1 = 0;
642 Int_t l2 = 0;
643 Int_t l3 = 0;
644
645 //maximal number of iterations
646 // Int_t nMaxIter = 100;
647
648 for(Int_t k = 0; k < nTracks; k++)
6f3f79de 649 {
6f3f79de 650
20d01a2f 651 if(switch1 == 1){
652 psum.SetXYZ(0., 0., 0.);
653 psum1 = 0;
654 for(Int_t i = 0; i < nTracks; i++)
655 {
656 psum1 += (TMath::Abs(n01.Dot(pTrackPerp[i])));
657 if (n01.Dot(pTrackPerp[i]) > 0) psum += pTrackPerp[i];
658 if (n01.Dot(pTrackPerp[i]) < 0) psum -= pTrackPerp[i];
659 }
660 thrust[l1] = psum1/psum2;
661 }
662
663 if(switch2 == 1){
664 psum02.SetXYZ(0., 0., 0.);
665 psum102 = 0;
666 for(Int_t i = 0; i < nTracks; i++)
667 {
668 psum102 += (TMath::Abs(n02.Dot(pTrackPerp[i])));
669 if (n02.Dot(pTrackPerp[i]) > 0) psum02 += pTrackPerp[i];
670 if (n02.Dot(pTrackPerp[i]) < 0) psum02 -= pTrackPerp[i];
671 }
672 thrust02[l2] = psum102/psum2;
673 }
674
675 if(switch3 == 1){
676 psum03.SetXYZ(0., 0., 0.);
677 psum103 = 0;
678 for(Int_t i = 0; i < nTracks; i++)
679 {
680 psum103 += (TMath::Abs(n03.Dot(pTrackPerp[i])));
681 if (n03.Dot(pTrackPerp[i]) > 0) psum03 += pTrackPerp[i];
682 if (n03.Dot(pTrackPerp[i]) < 0) psum03 -= pTrackPerp[i];
683 }
684 thrust03[l3] = psum103/psum2;
685 }
686
687 //check whether thrust value converged
688 if(TMath::Abs(th-thrust[l1]) < 10e-7){
689 switch1 = 0;
690 }
691
692 if(TMath::Abs(th02-thrust02[l2]) < 10e-7){
693 switch2 = 0;
694 }
695
696 if(TMath::Abs(th03-thrust03[l3]) < 10e-7){
697 switch3 = 0;
698 }
699
700 //if it didn't, continue with the calculation
701 if(switch1 == 1){
702 th = thrust[l1];
703 n01 = psum.Unit();
704 l1++;
705 }
706
707 if(switch2 == 1){
708 th02 = thrust02[l2];
709 n02 = psum02.Unit();
710 l2++;
711 }
712
713 if(switch3 == 1){
714 th03 = thrust03[l3];
715 n03 = psum03.Unit();
716 l3++;
717 }
718
719 //if thrust values for all starting direction converged check if to the same value
720 if(switch2 == 0 && switch1 == 0 && switch3 == 0){
721 if(TMath::Abs(th-th02) < 10e-7 && TMath::Abs(th-th03) < 10e-7 && TMath::Abs(th02-th03) < 10e-7){
722 eventShapes[0] = th;
e946cd3a 723 AliInfoGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),Form("===== THRUST VALUE FOUND AT %d :: %f\n", k, th));
20d01a2f 724 break;
725 }
726 //if they did not, reset switches
727 else{
728 switch1 = 1;
729 // th = -1.;
730 switch2 = 1;
731 // th02 = -2.;
732 switch3 = 1;
733 // th03 = -4.;
734 }
735 }
736
737 // Printf("========== %d +++ th :: %f=============\n", l1, th);
738 // Printf("========== %d +++ th2 :: %f=============\n", l2, th02);
739 // Printf("========== %d +++ th3 :: %f=============\n", l3, th03);
6f3f79de 740
6f3f79de 741 }
742
20d01a2f 743 //if no common limitng value was found, take the maximum and take the corresponding thrust axis
744 if(switch1 == 1 && switch2 == 1 && switch3 == 1){
745 eventShapes[0] = TMath::Max(thrust[l1-1], thrust02[l2-1]);
746 eventShapes[0] = TMath::Max(eventShapes[0], thrust03[l3-1]);
747 if(TMath::Abs(eventShapes[0]-thrust[l1-1]) < 10e-7)
748 n01 = n01;
749 if(TMath::Abs(eventShapes[0]-thrust02[l2-1]) < 10e-7)
750 n01 = n02;
751 if(TMath::Abs(eventShapes[0]-thrust03[l3-1]) < 10e-7)
752 n01 = n03;
753 Printf("NO LIMITING VALUE FOUND :: MAXIMUM = %f\n", eventShapes[0]);
754 }
6f3f79de 755
756//
757//other event shapes variables
758//
759 for(Int_t j = 0; j < nTracks; j++)
760 {
761 s00 = s00 + (pTrack[j].Px()*pTrack[j].Px())/pTrack[j].Mag();
762 s01 = s01 + (pTrack[j].Px()*pTrack[j].Py())/pTrack[j].Mag();
763 s02 = s02 + (pTrack[j].Px()*pTrack[j].Pz())/pTrack[j].Mag();
764
765 s10 = s10 + (pTrack[j].Py()*pTrack[j].Px())/pTrack[j].Mag();
766 s11 = s11 + (pTrack[j].Py()*pTrack[j].Py())/pTrack[j].Mag();
767 s12 = s12 + (pTrack[j].Py()*pTrack[j].Pz())/pTrack[j].Mag();
768
769 s20 = s20 + (pTrack[j].Pz()*pTrack[j].Px())/pTrack[j].Mag();
770 s21 = s21 + (pTrack[j].Pz()*pTrack[j].Py())/pTrack[j].Mag();
771 s22 = s22 + (pTrack[j].Pz()*pTrack[j].Pz())/pTrack[j].Mag();
772
773 ptot += pTrack[j].Mag();
774 }
775
776 if(ptot > 0.)
777 {
778 m(0,0) = s00/ptot;
779 m(0,1) = s01/ptot;
780 m(0,2) = s02/ptot;
781
782 m(1,0) = s10/ptot;
783 m(1,1) = s11/ptot;
784 m(1,2) = s12/ptot;
785
786 m(2,0) = s20/ptot;
787 m(2,1) = s21/ptot;
788 m(2,2) = s22/ptot;
789
790 TMatrixDSymEigen eigen(m);
791 TVectorD eigenVal = eigen.GetEigenValues();
792
793 Double_t sphericity = (3/2)*(eigenVal(2)+eigenVal(1));
794 eventShapes[1] = sphericity;
795
796 Double_t aplanarity = (3/2)*(eigenVal(2));
797 eventShapes[2] = aplanarity;
798
799 c = 3*(eigenVal(0)*eigenVal(1)+eigenVal(0)*eigenVal(2)+eigenVal(1)*eigenVal(2));
800 eventShapes[3] = c;
801 }
802 return kTRUE;
803}
804
805
806
807 //__________________________________________________________________________________________________________________________
59543510 808// Trigger Decisions copid from PWG0/AliTriggerAnalysis
809
810
811Bool_t AliAnalysisHelperJetTasks::IsTriggerFired(const AliVEvent* aEv, Trigger trigger)
812{
813 // checks if an event has been triggered
814 // no usage of ofline trigger here yet
edfbe476 815
7fa8b2da 816 // here we do a dirty hack to take also into account the
817 // missing trigger bits and Bunch crossing paatern for real data
edfbe476 818
819
7fa8b2da 820 if(aEv->InheritsFrom("AliESDEvent")){
cce8b687 821 const AliESDEvent *esd = (AliESDEvent*)aEv;
822 switch (trigger)
823 {
824 case kAcceptAll:
825 {
826 return kTRUE;
827 break;
828 }
829 case kMB1:
830 {
1c796df8 831 if(esd->GetFiredTriggerClasses().Contains("CINT1B-"))return kTRUE;
cd9a6fa2 832 // does the same but without or'ed V0s
edfbe476 833 if(esd->GetFiredTriggerClasses().Contains("CSMBB"))return kTRUE;
834 if(esd->GetFiredTriggerClasses().Contains("CINT6B-"))return kTRUE;
1c796df8 835 // this is for simulated data
836 if(esd->GetFiredTriggerClasses().Contains("MB1"))return kTRUE;
cce8b687 837 break;
838 }
839 case kMB2:
840 {
1c796df8 841 if(esd->GetFiredTriggerClasses().Contains("MB2"))return kTRUE;
cce8b687 842 break;
843 }
844 case kMB3:
845 {
1c796df8 846 if(esd->GetFiredTriggerClasses().Contains("MB3"))return kTRUE;
cce8b687 847 break;
848 }
849 case kSPDGFO:
850 {
cd9a6fa2 851 if(esd->GetFiredTriggerClasses().Contains("CSMBB"))return kTRUE;
edfbe476 852 if(esd->GetFiredTriggerClasses().Contains("CINT6B-"))return kTRUE;
1c796df8 853 if(esd->GetFiredTriggerClasses().Contains("GFO"))return kTRUE;
cce8b687 854 break;
855 }
856 default:
857 {
858 Printf("IsEventTriggered: ERROR: Trigger type %d not implemented in this method", (Int_t) trigger);
859 break;
860 }
861 }
862 }
863 else if(aEv->InheritsFrom("AliAODEvent")){
864 const AliAODEvent *aod = (AliAODEvent*)aEv;
7fa8b2da 865 switch (trigger)
866 {
867 case kAcceptAll:
868 {
cce8b687 869 return kTRUE;
7fa8b2da 870 break;
871 }
872 case kMB1:
873 {
cce8b687 874 if(aod->GetFiredTriggerClasses().Contains("CINT1B"))return kTRUE;
cd9a6fa2 875 // does the same but without or'ed V0s
876 if(aod->GetFiredTriggerClasses().Contains("CSMBB"))return kTRUE;
1c796df8 877 // for sim data
878 if(aod->GetFiredTriggerClasses().Contains("MB1"))return kTRUE;
7fa8b2da 879 break;
880 }
881 case kMB2:
882 {
1c796df8 883 if(aod->GetFiredTriggerClasses().Contains("MB2"))return kTRUE;
7fa8b2da 884 break;
885 }
886 case kMB3:
887 {
1c796df8 888 if(aod->GetFiredTriggerClasses().Contains("MB3"))return kTRUE;
7fa8b2da 889 break;
890 }
891 case kSPDGFO:
892 {
cce8b687 893 if(aod->GetFiredTriggerClasses().Contains("CSMBB"))return kTRUE;
1c796df8 894 if(aod->GetFiredTriggerClasses().Contains("GFO"))return kTRUE;
7fa8b2da 895 break;
896 }
897 default:
898 {
899 Printf("IsEventTriggered: ERROR: Trigger type %d not implemented in this method", (Int_t) trigger);
900 break;
901 }
902 }
903 }
cce8b687 904 return kFALSE;
59543510 905}
955d29ba 906
907
908 AliAnalysisHelperJetTasks::MCProcessType AliAnalysisHelperJetTasks::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
909
910 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader);
911
912 if (!pythiaGenHeader) {
fb03edbe 913 // printf(" AliAnalysisHelperJetTasks::GetProcessType : Unknown gen Header type). \n");
955d29ba 914 return kInvalidProcess;
915 }
916
917
918 Int_t pythiaType = pythiaGenHeader->ProcessType();
919 fgLastProcessType = pythiaType;
920 MCProcessType globalType = kInvalidProcess;
921
922
923 if (adebug) {
924 printf(" AliAnalysisHelperJetTasks::GetProcessType : Pythia process type found: %d \n",pythiaType);
925 }
926
927
928 if(pythiaType==92||pythiaType==93){
929 globalType = kSD;
930 }
931 else if(pythiaType==94){
932 globalType = kDD;
933 }
934 //else if(pythiaType != 91){ // also exclude elastic to be sure... CKB??
935 else {
936 globalType = kND;
937 }
938 return globalType;
939}
940
941
942 AliAnalysisHelperJetTasks::MCProcessType AliAnalysisHelperJetTasks::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
943 //
944 // get the process type of the event.
945 //
946
947 // can only read pythia headers, either directly or from cocktalil header
948 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader);
949
950 if (!dpmJetGenHeader) {
951 printf(" AliAnalysisHelperJetTasks::GetDPMjetProcessType : Unknown header type (not DPMjet or). \n");
952 return kInvalidProcess;
953 }
954
955 Int_t dpmJetType = dpmJetGenHeader->ProcessType();
956 fgLastProcessType = dpmJetType;
957 MCProcessType globalType = kInvalidProcess;
958
959
960 if (adebug) {
961 printf(" AliAnalysisHelperJetTasks::GetDPMJetProcessType : DPMJet process type found: %d \n",dpmJetType);
962 }
963
964
965 if (dpmJetType == 1 || dpmJetType == 4) { // explicitly inelastic plus central diffraction
966 globalType = kND;
967 }
968 else if (dpmJetType==5 || dpmJetType==6) {
969 globalType = kSD;
970 }
971 else if (dpmJetType==7) {
972 globalType = kDD;
973 }
974 return globalType;
975}
976