]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALJetMicroDst.cxx
codng convention
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALJetMicroDst.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2002, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 /* $Id$ */
18
19 //*-- Authors: Aleksei Pavlinov (WSU) 
20
21 //*
22
23 #include "AliEMCALJetMicroDst.h"
24 #include "AliRun.h"
25 #include "AliHeader.h"
26 #include "AliGenEventHeader.h"
27 #include "AliGenHijingEventHeader.h"
28 #include "AliEMCALJetFinder.h"
29 #include <TVector3.h>
30 #include <TROOT.h>
31 #include <TBrowser.h>
32 #include <TString.h>
33 #include <TParticle.h>
34 #include "AliMC.h"
35 #include <TH1.h>
36 #include <TH2.h>
37 #include <TH1F.h>
38
39
40 ClassImp(AliEMCALJetMicroDst)
41
42 TString nameTree("jetMDST"); // 7-feb-2002
43
44 //TH1F*  hPtPart, *hNJet, *hPtJet;
45 //TH2F*  hEtaPhiPart, *hEtaPhiJet;
46 //TH1F*  hNcell, *hCellId, *hCellEt, *hSumEt;
47 //TH1F*  hNgrid, *hGridId, *hGridEt, *hSumEtGrForJF;
48
49 extern "C" void sgpdge_(Int_t &i, Int_t &pdggea);
50
51 AliEMCALJetMicroDst::AliEMCALJetMicroDst(char *name, char *tit) : TNamed(name,tit)
52 {
53         //constructor
54   fFile  = 0;
55   fTree  = 0;
56   fDebug = 0;
57     
58 //  Don't add histos to the current directory
59 //  TH1::AddDirectory(0);
60   gROOT->cd();
61   hPtPart     = new TH1F("hPtPart","P_{T} for partons", 300, 0., 300.);
62   // 16-jan-2002 - new limit fo phi 
63   hEtaPhiPart = new TH2F("hEtaPhiPart","#eta #phi distr.for partons after HSc", 
64                        28, -0.7, 0.7, 21, 0.0, (2.0/3.0)*TMath::Pi());
65
66   hNJet  = new TH1F("hNJet","number of jets", 11, -0.5, 10.5);
67   hPtJet = new TH1F("hPtJet","P_{T} for jets", 500, 0., 500.);
68   hEtaPhiJet = new TH2F("hEtaPhiJet","#eta #phi distr.for jets (W)", 
69                        28, -0.7, 0.7, 21, 0.0, (2.0/3.0)*TMath::Pi());
70
71   hNcell  = new TH1F("hNcell","#cell with de>0.0 for EMCAL", 1400, 0.0, 14000.);
72   hCellId = new TH1F("hCellId","cell ID with de>0.0 for EMCAL", 1400, 0.0, 14000.);
73   hCellEt = new TH1F("hCellEt","cell Et for EMCAL", 1000, 0.0, 10.);
74   hSumEt  = new TH1F("hSumEt","sum Et for EMCAL", 1000, 0.0, 1000.);
75
76   hNgrid  = new TH1F("hNgrid","#cell with de>0.0 in EMCAL grid for JF", 1400, 0.0, 14000.);
77   hGridId = new TH1F("hGridId","cell ID with de>0.0 in EMCAL grid for JF", 1400, 0.0, 14000.);
78   hGridEt = new TH1F("hGridEt","cell Et in EMCAL grid for JF", 1000, 0.0, 10.);
79   hSumEtGrForJF  = new TH1F("hSumEtGrForJF","sum Et in EMCAL grid for JF", 1000, 0.0, 1000.);
80
81   fListHist = MoveHistsToList("Hist For AliEMCALJetMicroDst", kFALSE); 
82 }
83
84 AliEMCALJetMicroDst::~AliEMCALJetMicroDst()
85 {
86         //destructor
87   if(fFile) fFile->Close();
88 }  
89
90 Bool_t AliEMCALJetMicroDst::Create(TFile *file)
91 {
92   if(!file) {
93     Error("Create", "define TFile for output\n");
94     return kFALSE;
95   }
96   fFile     = file;
97   fFileName = fFile->GetName();
98   fFile->cd();
99   fTree = new TTree(nameTree.Data(),"Temporary micro DST for jets analysis");
100   // for jet calibration - 4-mar-2003
101   fTree->Branch("fdecone", &fdecone, "fdecone/F");
102   fTree->Branch("fptcone", &fptcone, "fptcone/F");
103   // partons 
104   fTree->Branch("fnpart", &fnpart, "fnpart/I");
105   fTree->Branch("fxpt",  fxpt,  "fxpt[fnpart]/F");
106   fTree->Branch("fxeta", fxeta, "fxeta[fnpart]/F");
107   fTree->Branch("fxphi", fxphi, "fxphi[fnpart]/F");
108   // jets 
109   fTree->Branch("fnjet", &fnjet, "fnjet/I");
110   fTree->Branch("fjet",  fjet,  "fjet[fnjet]/F");
111   fTree->Branch("fjetaw", fjetaw, "fjetaw[fnjet]/F");
112   fTree->Branch("fjphiw", fjphiw, "fjphiw[fnjet]/F");
113   fTree->Branch("fjetal", fjetal, "fjetal[fnjet]/F");
114   fTree->Branch("fjphil", fjphil, "fjphil[fnjet]/F");
115
116   // Et in EMCAL itself 
117   fTree->Branch("fncell", &fncell, "fncell/I");
118   fTree->Branch("fidcell", fidcell, "fidcell[fncell]/I");
119   fTree->Branch("fetcell", fetcell, "fetcell[fncell]/F");
120
121   // Et in EMCAL grid for JF 
122   fTree->Branch("fngrid", &fngrid,  "fngrid/I");
123   fTree->Branch("fidgrid", fidgrid, "fidgrid[fngrid]/I");
124   fTree->Branch("fetgrid", fetgrid, "fetgrid[fngrid]/F");
125
126   // charge particle which hit to EMCAL
127   fTree->Branch("fnchp", &fnchp, "fnchp/I");
128   fTree->Branch("fpid", fpid, "fpid[fnchp]/I");
129   fTree->Branch("fppt", fppt, "fppt[fnchp]/F");
130   fTree->Branch("fpeta", fpeta, "fpeta[fnchp]/F");
131   fTree->Branch("fpphi", fpphi, "fpphi[fnchp]/F");
132
133   return kTRUE;
134 }
135
136 Bool_t AliEMCALJetMicroDst::Create(const char *fname)
137 {
138         // Create member
139   TFile *file = new TFile(fname, "RECREATE");
140   if(file) {
141     //    fNameFile = fname;
142     return Create(file);
143   } else   return kFALSE;
144 }
145
146 Bool_t AliEMCALJetMicroDst::Open(const char *fname)
147 {
148         //Open member
149   if(fFile && fFile->IsOpen()) fFile->Close();
150   if(strlen(fname)) fName = fname;
151   TFile *file = new TFile(fName.Data(), "READ");
152   if(file) {
153     Bool_t ini =  Initialize(file);
154     Info("Open", "open file %s : initialize TTree %i",fName.Data(), Int_t(ini)); 
155     return ini;
156   } else {
157     Error("Open", "can not open file %s",fName.Data()); 
158     return kFALSE;
159   }
160 }
161
162 const Char_t* AliEMCALJetMicroDst::DefineName(const Int_t mode)
163 {
164         //DefineName member
165   static TString dir, name;
166   //  dir = "jetDST/"; // 24-jan-2003
167   dir = "/auto/alice/pavlinov/jet/microDST/"; // 24-jan-2003
168   switch (mode) {
169   case 1: // for characteristic of BG
170     name = dir + "mDst1_1.root"; // Bg 2000 - first version 
171     SetTitle("Bg2000");
172     break;
173   case 2: // for characteristic of BG
174     name = dir + "mDst2_1.root"; // Bg 4000 - first version 
175     SetTitle("Bg4000");
176     break;
177   case 3: // for characteristic of BG
178     name = dir + "mDst3_1.root"; // Bg 8000 - first version 
179     SetTitle("Bg8000");
180     break;
181   case 4: // Central Hijing - 18-mar-2003
182     name  = dir  + "march/";
183     name += "jF_R0.50MinCell1.0PtCut0.0EtSeed4.0MinEt40.0BGSubtr0SF11.6Smear0Eff0HijingCentral.root";
184     SetTitle("HijingCentral");
185     break;
186   case 5: // Para Hijing (Dn/Dy=8000) - 21-mar-2003
187     name  = dir  + "march/";
188     name += "jF_R0.50MinCell1.0PtCut0.0EtSeed4.0MinEt40.0BGSubtr0SF11.6Smear0Eff0ParaHijing8000.root";
189     SetTitle("HIJINGparaDnDy8000");
190     break;
191   case 6: // Para Hijing (Dn/Dy=4000) - 21-mar-2003
192     name  = dir  + "march/";
193     name += "jF_R0.50MinCell1.0PtCut0.0EtSeed4.0MinEt40.0BGSubtr0SF11.6Smear0Eff0ParaHijing4000.root";
194     SetTitle("HIJINGparaDnDy4000");
195     break;
196   case 7: // Para Hijing (Dn/Dy=2000) - 21-mar-2003
197     name  = dir  + "march/";
198     name += "jF_R0.50MinCell1.0PtCut0.0EtSeed4.0MinEt40.0BGSubtr0SF11.6Smear0Eff0ParaHijing2000.root";
199     SetTitle("HIJINGparaDnDy2000");
200     break;
201   case 11: // pure PYTHIA with default value of parameters
202     name = dir + "jF_R0.50MinCell0.0PtCut0.0EtSeed8.0MinEt40.0BGSubtr0SF11.6.root";
203     break;
204   case 12: // 0 + background 
205     name = dir + "jF_R0.50MinCell0.0PtCut0.0EtSeed8.0MinEt40.0BGSubtr0SF11.6kBackground2000.root";
206     break;
207     // calibration case 
208   case 101:
209     name  = dir  + "march/";
210     name += "Pythia100_1.root";
211     SetTitle("Pythia100_1");
212     break;
213   case 102: // 2-apr-2003
214     name  = dir  + "march/";
215     name += "Pythia50_1.root";
216     SetTitle("Pythia50_1");
217     //    name = "microDst3th.root"; // 101 + (smearing and eff) - 14-mar-2003
218     break;
219   case 103:// 4-apr-2003
220     name  = dir  + "march/";
221     name += "Pythia200_1.root";
222     SetTitle("Pythia200_1");
223     //    name = "microDst4th.root"; // 102 + MinCell= 1.0
224     break;
225   default:
226     Fatal("DefineName", "NO  D E F A U L T : mode %i\n", mode);
227   }
228   Info("DefineName", "mode %5i file : %s : Title %s\n", mode, name.Data(), GetTitle());
229   return name.Data();
230 }
231
232 Bool_t AliEMCALJetMicroDst::Initialize(TFile *file)
233 {
234         // Initialize method
235   if(file) fFile = file; 
236   fFile->cd();
237   fTree = (TTree*)fFile->Get(nameTree.Data());
238   if(!fTree) return kFALSE;
239   // for jet calibration - 4-mar-2003
240   fTree->SetBranchAddress("fdecone",&fdecone);
241   fTree->SetBranchAddress("fptcone",&fptcone);
242   // partons
243   fTree->SetBranchAddress("fnpart",&fnpart);
244   fTree->SetBranchAddress("fxpt",   fxpt);
245   fTree->SetBranchAddress("fxeta",  fxeta);
246   fTree->SetBranchAddress("fxphi",  fxphi);
247   // jets 
248   fTree->SetBranchAddress("fnjet", &fnjet);
249   fTree->SetBranchAddress("fjet",   fjet);
250   fTree->SetBranchAddress("fjetaw", fjetaw);
251   fTree->SetBranchAddress("fjphiw", fjphiw);
252   fTree->SetBranchAddress("fjetal", fjetal);
253   fTree->SetBranchAddress("fjphil", fjphil);
254   // eT in EMCAL
255   fTree->SetBranchAddress("fncell", &fncell);
256   fTree->SetBranchAddress("fidcell", fidcell);
257   fTree->SetBranchAddress("fetcell", fetcell);
258   // eT in EMCAL grid for JF
259   fTree->SetBranchAddress("fngrid", &fngrid);
260   fTree->SetBranchAddress("fidgrid", fidgrid);
261   fTree->SetBranchAddress("fetgrid", fetgrid);
262   // 28-jan-2003
263   fTree->SetBranchAddress("fnchp", &fnchp);
264   fTree->SetBranchAddress("fpid", fpid);
265   fTree->SetBranchAddress("fppt", fppt);
266   fTree->SetBranchAddress("fpeta", fpeta);
267   fTree->SetBranchAddress("fpphi", fpphi);
268
269   return kTRUE;
270 }
271
272 void AliEMCALJetMicroDst::Print(Option_t* option) const
273 {
274         // 
275   if(option);
276   if(fFile) {
277     fFile->Print();
278     if(fTree) fTree->Print();
279     else Info("Print", "TRee is zero\n");
280   } else {
281      Info("Print", "File with TRee is closed \n Name of file %s(from fFileName", fFileName.Data());
282   }
283
284   Info("Print", "******* Current(last) event *****");
285   printf("#partons %2i \n", fnpart);
286   for(Int_t i=0; i<fnpart; i++){
287     printf("     %1i Pt %7.1f eta  %7.4f phi  %7.4f \n",
288     i, fxpt[i],fxeta[i],fxphi[i]);  
289   }
290   printf("#jets    %2i \n", fnjet);
291   for(Int_t i=0; i<fnjet; i++){
292     printf("     %1i Et %7.1f etaw %7.4f phiw %7.4f \n",
293     i,fjet[i],fjetaw[i],fjphiw[i]);  
294   }
295   printf(" Title %s \n", GetTitle());
296 }
297
298 void AliEMCALJetMicroDst::Fill(AliRun *run, AliEMCALJetFinder* jetFinder, Int_t modeFilling)
299 {//  modeFilling >=1 - fill info for EMCAL grid
300   if(!run) run = gAlice;
301   AliGenEventHeader* evHeader = run->GetHeader()->GenEventHeader();
302   TString tmp(evHeader->ClassName());
303   if(tmp.Contains("Hijing")) {
304      AliGenHijingEventHeader *hijEvHeader = (AliGenHijingEventHeader*)evHeader;
305      FillPartons(hijEvHeader);
306   } else if(tmp.Contains("Pythia")) {
307      FillPartons();     
308   } else {
309     Error("Fill", "Wrong type of generator -> %s \n Info about partons will be absent",tmp.Data()); 
310   }
311
312   FillJets(jetFinder);
313
314   if(modeFilling >= 1) {
315      FillEtForEMCAL(jetFinder);
316      FillEtForGrid(jetFinder);
317      FillChargeParticles(jetFinder);
318   } else {
319      fncell = 0; // 27-jan-2003
320      fngrid = 0; // 27-jan-2003
321      fnchp  = 0;
322      // negative - no signal 
323      fdecone = -1.;
324      fptcone = -1.;
325   }
326
327   FillJetsControl();  //24-jan-2003
328
329   fTree->Fill();
330 }
331
332 void AliEMCALJetMicroDst::FillPartons(AliGenHijingEventHeader *header)
333 {
334   TLorentzVector parton[4];
335   header->GetJets(parton[0], parton[1], parton[2], parton[3]);
336
337   fnpart = 4; // 
338   for(Int_t i=0; i<4; i++){
339      fxpt[i]  = parton[i].Pt();
340      fxeta[i] = parton[i].Eta();
341      fxphi[i] = parton[i].Phi();
342   }
343 }
344
345 void AliEMCALJetMicroDst::FillPartons()
346 {// for case of Pythia -> get info from full event record
347
348   fnpart = 2;
349   TParticle *mPart;
350   Int_t ind;
351   for(Int_t i=6; i<8; i++){
352      mPart = gAlice->GetMCApp()->Particle(i);
353      ind   = i-6;
354      fxpt[ind]  = mPart->Pt();
355      fxeta[ind] = mPart->Eta();
356      fxphi[ind] = mPart->Phi();
357   }
358 }
359
360 void AliEMCALJetMicroDst::FillJets(AliEMCALJetFinder* jetFinder)
361 {
362   fnjet = 0;
363   if(fDebug>1) Info("FillJets", "Debug"); 
364   if(!jetFinder) {
365     if(fDebug>1) Info("FillJets", "jetFinder is zero"); 
366     return;
367   }
368   fnjet = jetFinder->Njets();
369   if(fnjet>10) {
370     if(fDebug>1) Warning("FillJets", "wrong value of jetFinder->Njets() %i ", fnjet); 
371     fnjet = 10;
372   }
373   //  hNJet->Fill(njet);
374   if(fDebug>1) Info("FillJets", "njet %i", fnjet); 
375   if(fnjet){
376     for(Int_t i=0; i<fnjet; i++){
377       fjet[i]   = jetFinder->JetEnergy(i);
378       fjetaw[i] = jetFinder->JetEtaW(i);
379       fjphiw[i] = jetFinder->JetPhiW(i);
380       fjetal[i] = jetFinder->JetEtaL(i);
381       fjphil[i] = jetFinder->JetPhiL(i);
382     }
383   }
384 }
385
386 void AliEMCALJetMicroDst::FillEtForEMCAL(AliEMCALJetFinder* jetFinder)
387 {
388    fncell = 0;
389    TH2F *hid = jetFinder->GetLegoEMCAL();
390    if(!hid) return;
391
392    Double_t de = 0.;
393    Int_t neta = hid->GetNbinsX(), nphi = hid->GetNbinsY();
394    for(Int_t ieta=1; ieta<=neta; ieta++) {
395       for(Int_t iphi=1; iphi<=nphi; iphi++) {
396          de = hid->GetBinContent(ieta,iphi);
397          if(de > 0.0) {
398            fetcell[fncell] = Float_t(de);
399            fidcell[fncell] = nphi*(ieta-1) + iphi;
400            fncell++;
401            if(fncell >= 13824) break; 
402            // Info("FillEtForEMCAL", " ncell %i6 id %i6 de %f \n", ncell, idcell[ncell], etcell[ncell]); 
403          }
404       }
405    }
406    if(fnjet == 1) {
407      // jet energy calculate around LP direction !!! - 10-mar-2003 
408       fdecone = jetFinder->EMCALConeEnergy(fjetal[0],fjphil[0]); 
409       fptcone = jetFinder->TrackConeEnergy(fjetal[0],fjphil[0]); // get from lego plot fo ch.part
410       Info("FillEtForEMCAL", " njet %i Emcal in cone %f pt ch.part in cone %f\n", fnjet, fdecone, fptcone); 
411       Info("FillEtForEMCAL", " jet - decone - ptcone : %9.2f\n", fjet[0]-fdecone-fptcone);
412    } else {
413       fdecone = -1.;
414       fptcone = -1.;
415    }
416
417    Info("FillEtForEMCAL", "neta %3i nphi %3i # array size %i Sum.Et %f\n", 
418    neta,nphi, fncell, hid->Integral());
419 }
420
421 void AliEMCALJetMicroDst::FillEtForGrid(AliEMCALJetFinder* jetFinder)
422 {
423    TH2F *hid = jetFinder->GetLego();
424    if(!hid) return;
425
426    FillArrays(hid, fngrid, fidgrid, fetgrid);
427 }
428
429 void AliEMCALJetMicroDst::FillArrays(TH2* hid, Int_t &n, Int_t *id, Float_t *et)
430 {
431    n = 0;
432    Double_t de = 0.;
433    Int_t neta = hid->GetNbinsX(), nphi = hid->GetNbinsY();
434    for(Int_t ieta=1; ieta<=neta; ieta++) {
435       for(Int_t iphi=1; iphi<=nphi; iphi++) {
436          de = hid->GetBinContent(ieta,iphi);
437          if(de > 0.0) {
438            et[n] = Float_t(de);
439            id[n] = nphi*(ieta-1) + iphi;
440            n++;
441            if(n >= 13824) break; 
442          }
443       }
444    }
445    Info("FillArrays", "neta %3i nphi %3i # array size %i Sum.Et %f\n", 
446    neta, nphi, n, hid->Integral());
447 }
448
449 void AliEMCALJetMicroDst::FillChargeParticles(AliEMCALJetFinder* jetFinder)
450 {// 28-jan-2003 for fullness ; 18-mar - sometimes 
451   fnchp = 0;
452   Int_t gid=0;
453   for(Int_t i=0; i<jetFinder->fNt; i++) {
454     //     fPdgT[i];
455      if(jetFinder->fTrackList[i] >= 1) {
456         sgpdge_(jetFinder->fPdgT[i], gid);
457         fpid[fnchp]  = gid; 
458         fppt[fnchp]  = jetFinder->fPtT[i];
459         fpeta[fnchp] = jetFinder->fEtaT[i];
460         fpphi[fnchp] = jetFinder->fPhiT[i];
461         fnchp++;
462      }
463   }
464   Info("FillChargedParticles", "fNtS %i : nchp %i -> %i\n", jetFinder->fNtS, fnchp, jetFinder->fNtS - fnchp);
465 }
466
467 void AliEMCALJetMicroDst::FillJetsControl()
468 {  // see FillJets(AliEMCALJetFinder* jetFinder) and FillPartons
469   hNJet->Fill(fnjet);
470   for(Int_t i=0; i<fnjet; i++){
471      hPtJet->Fill(fjet[i]);
472      hEtaPhiJet->Fill(fjetaw[i],fjphiw[i]); 
473   }
474
475   for(Int_t i=0; i < fnpart; i++){
476      hEtaPhiPart->Fill(fxeta[i], fxphi[i]);
477      hPtPart->Fill(fxpt[i]);
478   }
479
480   Double_t sum = 0.0;
481   hNcell->Fill(fncell);
482   for(Int_t i=0; i < fncell; i++){
483     hCellId->Fill(fidcell[i]);
484     hCellEt->Fill(fetcell[i]);
485     sum += Double_t(fetcell[i]);
486   }
487   hSumEt->Fill(sum);
488
489   sum = 0.0;
490   hNgrid->Fill(fngrid);
491   for(Int_t i=0; i < fngrid; i++){
492     hGridId->Fill(fidgrid[i]);
493     hGridEt->Fill(fetgrid[i]);
494     sum += Double_t(fetgrid[i]);
495   }
496   hSumEtGrForJF->Fill(sum);
497 }
498
499 Int_t AliEMCALJetMicroDst::GetEntry(Int_t entry)
500 { // Read contents of entry.
501    if (!fTree) {
502       Error("GetEntry", "define TTree");
503       return -1;
504    }
505    return fTree->GetEntry(entry);
506 }
507
508 Bool_t AliEMCALJetMicroDst::GetParton(Int_t i, Float_t& pt, Float_t& eta, Float_t& phi)
509 {
510   if(i>=0 && i<fnpart) {
511     pt  = fxpt[i];
512     eta = fxeta[i];
513     phi = fxphi[i];
514     return kTRUE;
515   } else return kFALSE; 
516 }
517
518 Bool_t AliEMCALJetMicroDst::GetParton(Int_t i, TVector3& vec)
519 {
520   static Float_t pt, eta, phi;
521
522   if(!GetParton(i, pt, eta, phi)) return kFALSE;
523
524   FillVector(pt, eta, phi, vec);
525   return kTRUE;
526 }
527
528 Bool_t AliEMCALJetMicroDst::GetJet(Int_t i,Int_t mode,Float_t& pt, Float_t& eta, Float_t& phi)
529 {// mode=1(W) mode=any(L)
530   if(i>=0 && i<fnjet) {
531     pt  = fjet[i];
532     if(mode==1) {
533       eta = fjetaw[i];
534       phi = fjphiw[i];
535     } else {
536       eta = fjetal[i];
537       phi = fjphil[i];
538     }
539     return kTRUE;
540   } else return kFALSE; 
541 }
542
543 Bool_t AliEMCALJetMicroDst::GetJet(Int_t i, Int_t mode, TVector3& vec)
544 {
545   static Float_t pt, eta, phi;
546
547   if(!GetJet(i, mode, pt, eta, phi)) return kFALSE;
548   FillVector(pt, eta, phi, vec);
549   return kTRUE;
550 }
551
552 void AliEMCALJetMicroDst::Test()
553 {
554   if(!fFile || !fTree ) {
555     Info("Test", "define file with proper TTree !");
556     return;
557   }
558   Int_t nbytes=0, nb=0, nentries=Int_t(fTree->GetEntries());
559   for(Int_t i=0; i<nentries; i++){
560     nb = fTree->GetEntry(i);  
561     nbytes += nb;
562     for(Int_t j=0; j<fnpart; j++){
563       hEtaPhiPart->Fill(fxeta[j], fxphi[j]);
564       hPtPart->Fill(fxpt[j]);
565     }
566
567     hNJet->Fill(fnjet);
568     if(fnjet){
569       for(Int_t j=0; j<fnjet; j++) {
570         hPtJet->Fill(fjet[j]);
571         hEtaPhiJet->Fill(fjetaw[j],fjphiw[j]); 
572       }
573     }
574   }
575   Info("Test", "Entries %5i Bytes %10i\n", nentries, nbytes);
576 }
577
578 void AliEMCALJetMicroDst::FillVector(Float_t pt, Float_t eta, Float_t phi, TVector3& vec)
579 { // service function 
580   static Float_t px, py, pz;
581
582   px = pt*TMath::Cos(phi);
583   py = pt*TMath::Sin(phi);
584   pz = pt*TMath::SinH(eta);  // sinh(eta) = cot(theta)
585
586   vec.SetXYZ(px, py, pz);
587 }
588
589 void AliEMCALJetMicroDst::GetEtaPhi(Int_t id, Double_t &eta, Double_t &phi)
590 { // see AliEMCALGeometry 
591   static Int_t ieta, iphi, nphi=144, neta=96;
592   static Double_t phiMax=(2.0/3.0)*TMath::Pi(), phiMin=0.0;
593   static Double_t phiStep=(phiMax-phiMin)/nphi, phiBeg = phiMin + phiStep/2.; 
594   static Double_t etaMax=0.7, etaMin=-etaMax;
595   static Double_t etaStep=(etaMax-etaMin)/neta, etaBeg = etaMin + etaStep/2.;
596
597   ieta = (id-1)/nphi + 1; // id = nphi*(ieta-1) + iphi
598   iphi = id - nphi*(ieta-1);
599   if(ieta<=0 || ieta>neta) {
600     Fatal("GetEtaPhi", "wrong id %i(ieta %i,iphi %i) : nphi %i neta %i", id,iphi,ieta, nphi,neta);
601
602   }
603
604   eta  = etaBeg + etaStep*(ieta-1);
605   phi  = phiBeg + phiStep*(iphi-1);
606 }
607
608 TVector3& AliEMCALJetMicroDst::GetCellVector(Int_t i)
609 {
610   static Double_t eta,phi;
611   static TVector3 vec;
612   vec.SetXYZ(0.,0.,0.);
613   if(i>=0 && i<fncell) {
614      GetEtaPhi(fidcell[i], eta, phi);
615      vec.SetPtEtaPhi(Double_t(fetcell[i]),eta,phi);
616   }
617   return vec;
618 }
619
620 TVector3& AliEMCALJetMicroDst::GetGridVector(Int_t i)
621 {
622   static Double_t eta,phi;
623   static TVector3 vec;
624   vec.SetXYZ(0.,0.,0.);
625   if(i>=0 && i<fngrid) {
626      GetEtaPhi(fidgrid[i], eta, phi);
627      vec.SetPtEtaPhi(Double_t(fetgrid[i]),eta,phi);
628   }
629   return vec;
630 }
631
632 Double_t AliEMCALJetMicroDst::GetSumInCone(TVector3 &jet,Int_t nc, Float_t *et,Float_t *eta,Float_t *phi, Double_t cellEtCut, Double_t rJet)
633 {
634   static Double_t sum=0.;
635   static TVector3 cell(0., 0., 0.);
636   if(nc<=0 || et==0 || eta==0 || phi==0) {
637     Error("GetSumInCone", "nc %d %f %f %f ", nc, et, eta, phi);
638     return -1.;
639   }
640
641   sum=0.;
642   //  jet.SetPtEtaPhi(jet[0],jetaw[0],jphiw[0]); // must be one jet !!
643   Info("GetSumInCone", "jet.Mag() %f : njet %i\n", jet.Mag(), fnjet);
644   for(Int_t i=0; i<nc; i++){
645     if(et[i] < cellEtCut)    continue;
646     cell.SetPtEtaPhi(et[i], eta[i], phi[i]);
647     if(jet.DeltaR(cell) > rJet) continue;
648     sum += et[i];
649   }
650   Info("GetSumCone", "Sum %f \n", sum);
651   return sum;
652 }
653
654 Double_t AliEMCALJetMicroDst::GetEmcalEtInCone(TVector3 &jet, Double_t cellEtCut, Double_t rJet)
655 {
656   Int_t nc = fncell;
657   if(nc<=0) return 0.;
658
659   Float_t *et=fetcell, *eta=new Float_t[nc], *phi=new Float_t[nc];
660   Double_t etaCell=0., phiCell=0., eTotal=0;
661
662   for(Int_t i=0; i<nc; i++) {
663     GetEtaPhi(fidcell[i], etaCell, phiCell);
664     eta[i] = etaCell;
665     phi[i] = phiCell;
666   }
667
668   eTotal = GetSumInCone(jet, nc, et,eta,phi, cellEtCut,rJet);
669   delete [] eta;
670   delete [] phi;
671
672   return eTotal;
673 }
674
675 Double_t AliEMCALJetMicroDst::GetTpcPtInCone(TVector3 &jet,Double_t cellEtCut, Double_t rJet)
676 {
677   if(fnchp<=0) return 0.;
678   return GetSumInCone(jet, fnchp, fppt,fpeta,fpphi, cellEtCut,rJet);
679 }
680
681 Double_t AliEMCALJetMicroDst::GetSum(Int_t n, Float_t *ar, Double_t cut)
682 { // 25-apr-2003
683   Double_t sum=0.0;
684   if(n<=0 || ar==0) return sum;
685   for(Int_t i=0; i<n; i++) {if(ar[i]>=cut) sum += Double_t(ar[i]);}
686   return sum;
687 }
688
689 void AliEMCALJetMicroDst::Close()
690 {
691   fFile->Write(); 
692   fTree->Print(); 
693   fFile->Close();
694   fFile = 0;
695   fTree = 0;
696 }
697
698 void AliEMCALJetMicroDst::Browse(TBrowser* b)
699 {
700    if(fTree)      b->Add((TObject*)fTree);
701    if(fListHist)  b->Add((TObject*)fListHist);
702    //   TObject::Browse(b);
703 }
704
705 Bool_t  AliEMCALJetMicroDst::IsPythiaDst()
706 {
707   TString st(GetTitle());
708   if(st.Contains("py",TString::kIgnoreCase)||!st.Contains("hijing", TString::kIgnoreCase)) return kTRUE;
709   else return kFALSE;
710 }
711
712 Bool_t  AliEMCALJetMicroDst::IsFolder() const
713 {
714   if(fTree || fListHist) return kTRUE;
715   else                   return kFALSE;
716 }
717
718 TList* AliEMCALJetMicroDst::MoveHistsToList(char* name, Bool_t putToBrowser)
719 {
720   gROOT->cd();
721   TIter nextHist(gDirectory->GetList());
722   TList *list = new TList;
723   list->SetName(name);
724   TObject *objHist;
725   while((objHist=nextHist())){
726     if (!objHist->InheritsFrom("TH1")) continue;
727     ((TH1*)objHist)->SetDirectory(0); // Remove from gROOT
728     list->Add(objHist);
729   }
730   if(putToBrowser) gROOT->GetListOfBrowsables()->Add((TObject*)list);
731   return list;
732 }