]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AnaPhotons_v1.C
Compiled aliroot macro for the analysis of neutrla mesons in PHOS
[u/mrichter/AliRoot.git] / PHOS / AnaPhotons_v1.C
1 //===============================================================
2 // In this Macro (which can (must) be compilated), you will find all the 
3 // analysis functions to build photon spectrum, invariant mass 
4 // spectrum of photon  pairs and combinatorial background calculations 
5 // in ALICE electromagnetic calorimeter
6 // Author: Gines MARTINEZ, Subatech, 15 june 2001
7 //============================================================== 
8 #include "TH2.h"
9 #include "TH1.h"
10 #include "TFile.h"
11 #include "TTree.h"
12 #include "TRandom.h"
13 #include "TObjectTable.h"
14 #include "AliRun.h"
15 #include "AliPHOSGetter.h"
16 #include "AliPHOSRecParticle.h"
17 #include "TLorentzVector.h"
18 #include "TGraphErrors.h"
19 #include "TF1.h"
20
21 TObjectTable * gObjectTable;
22 TRandom      * gRandom;
23 AliRun       * gAlice;
24
25
26 void AnaMinv(char * filename)
27 {
28   TH2F * h_Minv_lowpT       = new TH2F("h_Minv_lowpT","Minv vs pT low",500,0.0,1.0,40,0.,10.);
29   TH2F * h_Minv_highpT      = new TH2F("h_Minv_highpT","Minv vs pT high",500,0.0,1.0,50,0.,100.);
30   TH2F * h_Minv_lowpT_back  = new TH2F("h_Minv_lowpT_back","Minv vs pT low back",500,0.0,1.0,40,0.,10.);
31   TH2F * h_Minv_highpT_back = new TH2F("h_Minv_highpT_back","Minv vs pT high back",500,0.0,1.0,50,0.,100.);
32
33
34   TH1F * h_Pseudoeta = new TH1F("h_Pseudoeta","Pseudoeta photons",500,-1.0,1.0);
35   TH1F * h_Pt        = new TH1F("h_Pt","Pt photons",400,0.,10.);
36   TH2F * h_Peta_Pt   = new TH2F("h_Peta_Pt","Pseudo vs pT",40,0.,10.,50,-1.0,1.0);
37   TH1F * h_Phi       = new TH1F("h_Phi","Phi photons",400,-4.,4.);
38   TH2F * h_Peta_Phi  = new TH2F("h_Peta_Phi","Pseudo vs Phi",200,-4,4,200,-1.0,1.0);
39   TH1F * h_Dispersion= new TH1F("h_Dispersion","Dispersion",50,0.,10.);
40   TH1F * h_Type      = new TH1F("h_Type","Particle Type",10,0.,10.);
41
42   TH1F * h_DeltaR   = new TH1F("h_DeltaR","Delta R",400,0.,2.);
43   TH1F * h_Asymmetry= new TH1F("h_Asymmetry","Asymmetry",400, -2., 2.);
44
45   AliPHOSGetter * RecData = AliPHOSGetter::GetInstance(filename,"Gines")  ;
46  
47   AliPHOSRecParticle * RecParticle1;
48   AliPHOSRecParticle * RecParticle2;
49
50   Float_t RelativeRCut = 0.00001 ; 
51   Float_t AsymmetryCut = 0.7 ;
52   Float_t Asymmetry;
53   Float_t Type;
54
55   Int_t iEvent, iRecParticle1, iRecParticle2;
56   Int_t nRecParticle;
57   Float_t invariant_mass, invariant_mass_mixed;
58  
59   Float_t average_multiplicity = 0.;
60
61   for(iEvent=0; iEvent<gAlice->TreeE()->GetEntries(); iEvent++)
62     {
63       TLorentzVector P_photon1, P_photon2, P_photonMixed1, P_photonMixed2 ;
64
65       RecData->Event(iEvent);
66       printf(">>> Event %d \n",iEvent);
67       nRecParticle=RecData->NRecParticles();
68       average_multiplicity += ((Float_t) (nRecParticle) ) / ( (Float_t)gAlice->TreeE()->GetEntries() ) ;
69       // Construction de la masse invariante des pairs
70       if (nRecParticle > 1) 
71         {
72           for(iRecParticle1=0; iRecParticle1<nRecParticle; iRecParticle1++)
73             {
74               RecParticle1 = (AliPHOSRecParticle *)  RecData->RecParticle(iRecParticle1);
75               RecParticle1->Momentum(P_photon1);
76               Type = RecParticle1->GetType();
77               h_Type->Fill(Type);
78         
79
80               h_Pseudoeta->Fill(P_photon1.PseudoRapidity());
81               h_Pt->Fill(P_photon1.Pt());
82               h_Phi->Fill(P_photon1.Phi());
83               h_Peta_Pt->Fill(P_photon1.Pt(), P_photon1.PseudoRapidity());
84               h_Peta_Phi->Fill(P_photon1.Phi(), P_photon1.PseudoRapidity() );
85             
86               for(iRecParticle2=iRecParticle1+1; iRecParticle2<nRecParticle; iRecParticle2++)
87                 {
88                   RecParticle2 = (AliPHOSRecParticle *)  RecData->RecParticle(iRecParticle2);
89                   RecParticle2->Momentum(P_photon2); 
90                   Asymmetry = TMath::Abs((P_photon1.E()-P_photon2.E())/(P_photon1.E()+P_photon2.E()));
91                   if ( (P_photon1 != P_photon2) && 
92                        (P_photon1.DeltaR(P_photon2) > RelativeRCut) &&
93                        (Asymmetry < AsymmetryCut)                          )
94                     {
95                       h_DeltaR->Fill(P_photon1.DeltaR(P_photon2));
96                       h_Asymmetry->Fill( Asymmetry );
97
98                       //   printf("A. p1 es %f \n",P_photon1->E());
99                       invariant_mass = (P_photon1 + P_photon2).M();
100                       // printf("B. p1 es %f \n",P_photon1->E());
101                       h_Minv_lowpT->Fill(invariant_mass, (P_photon1 + P_photon2).Pt() );
102                       h_Minv_highpT->Fill(invariant_mass,(P_photon1 + P_photon2).Pt() );
103                     }  
104                 }
105             }
106         }
107     }
108   printf(">>> Average Multiplicity is %f \n",average_multiplicity);
109   Int_t Background = (Int_t)  (gAlice->TreeE()->GetEntries() * average_multiplicity * (average_multiplicity-1.)/2.) ;
110   printf(">>> Background is %d \n",Background);
111
112   Double_t Pt_Mixed1, Pt_Mixed2;
113   Double_t Y_Mixed1, Y_Mixed2;
114   Double_t Phi_Mixed1, Phi_Mixed2;
115
116   for(iEvent=0; iEvent<Background; iEvent++)
117     {
118       TLorentzVector P_photon1, P_photon2, P_photonMixed1, P_photonMixed2 ;
119       //      printf(">>> Background Event %d \n",iEvent);
120       Pt_Mixed1 =  h_Pt->GetRandom(); 
121       Pt_Mixed2 =  h_Pt->GetRandom();
122       h_Peta_Phi->GetRandom2(Phi_Mixed1, Y_Mixed1);
123       h_Peta_Phi->GetRandom2(Phi_Mixed2, Y_Mixed2);
124       P_photonMixed1.SetPtEtaPhiM( Pt_Mixed1, Y_Mixed1, Phi_Mixed1, 0.0);
125       P_photonMixed2.SetPtEtaPhiM( Pt_Mixed2, Y_Mixed2, Phi_Mixed2, 0.0);
126       Asymmetry = TMath::Abs((P_photonMixed1.E()-P_photonMixed2.E())/(P_photonMixed1.E()+P_photonMixed2.E()));
127       
128       if ( (P_photonMixed1.DeltaR(P_photonMixed2) > RelativeRCut) &&
129            (Asymmetry < AsymmetryCut  )                               )
130         {
131           invariant_mass_mixed = (P_photonMixed1 + P_photonMixed2).M();
132           h_Minv_lowpT_back->Fill(invariant_mass_mixed, (P_photonMixed1 + P_photonMixed2).Pt() );
133           h_Minv_highpT_back->Fill(invariant_mass_mixed,(P_photonMixed1 + P_photonMixed2).Pt() );
134         }  
135     }
136   
137
138   char outputname[80];
139   sprintf(outputname,"%s.Minv",filename);
140   TFile output(outputname,"recreate");
141   h_Minv_lowpT->Write();
142   h_Minv_highpT->Write();
143   h_Minv_lowpT_back->Write();  
144   h_Minv_highpT_back->Write();
145   h_Pseudoeta->Write();
146   h_Pt->Write();
147   h_Peta_Pt->Write();
148   h_Phi->Write();
149   h_Peta_Phi->Write();
150   h_Dispersion->Write();
151   h_Type->Write();
152   h_Asymmetry->Write();
153   h_DeltaR->Write();
154   
155   output.Close();
156 }
157
158
159 void AnaPtSpectrum(char * filename, Int_t NumberPerPtBin, Option_t * particle, Option_t * opt)
160 {
161
162   Int_t NumberOfPtBins = NumberPerPtBin;
163   Float_t PtCalibration = 0.250;
164
165   TFile * in = new TFile(filename);
166
167   TH2F * h_Minv_pT = 0;  
168   TH2F * h_Minv_pT_back = 0; 
169   TH2F * frame = 0 ;
170
171   if (strstr(opt,"low"))
172     {
173       h_Minv_pT      = (TH2F *) in->Get("h_Minv_lowpT"); ;
174       h_Minv_pT_back = (TH2F *) in->Get("h_Minv_lowpT_back");
175       PtCalibration  = 0.250;   
176       frame = new TH2F("PtSpectrumlow","Pt Spectrum low",10, 0.,10.,10,0.1,10000);
177     }  
178   if (strstr(opt,"high"))
179     {
180       h_Minv_pT      = (TH2F *) in->Get("h_Minv_highpT"); ;
181       h_Minv_pT_back = (TH2F *) in->Get("h_Minv_highpT_back");
182       PtCalibration = 2.5;
183       frame = new TH2F("PtSpectrumhigh","Pt Spectrum high",10, 0.,100.,10,0.1,10000);
184     }
185
186   if ( h_Minv_pT == 0 ) 
187     {
188       printf(">>> Bad Option! \n");
189       return;
190     }
191   Int_t Norma_1 = 100; Float_t Norma_minv_1 = 0.2;
192   Int_t Norma_2 = 200; Float_t Norma_minv_2 = 0.4;
193
194   Int_t Minv_1 = 46;
195   Int_t Minv_2 = 76;
196   if (strstr(particle,"eta"))
197     {
198       Minv_1 = 214;
199       Minv_2 = 314;
200     }
201
202   if (strstr(particle,"norma"))
203     {
204       Minv_1 = 100;
205       Minv_2 = 200;
206     }
207   
208   Int_t NHistos = 40/NumberOfPtBins;
209   Int_t iHistos;
210
211   TH1D * signal = 0;
212   TH1D * background = 0;
213   TH1D * ratio = 0;
214   TH1D * difference = 0;
215
216   Float_t Pt[NHistos];
217   Float_t PtError[NHistos];
218   Float_t Nmesons[NHistos];
219   Float_t NmesonsError[NHistos];
220
221   Float_t Ntota, Nback, Norma, NormaError, Renorma;
222
223   for(iHistos=0; iHistos<NHistos; iHistos++)
224     {
225       signal     = h_Minv_pT->ProjectionX("signal",         NumberOfPtBins*iHistos+1,NumberOfPtBins*(iHistos+1));
226       background = h_Minv_pT_back->ProjectionX("background",NumberOfPtBins*iHistos+1,NumberOfPtBins*(iHistos+1));
227       
228       ratio = new TH1D(*signal);
229       ratio->Sumw2(); 
230       ratio->Add(background,-1.0);
231       ratio->Divide(background);
232       difference = new TH1D(*signal);
233       difference->Sumw2();
234       ratio->Fit("pol0","","",Norma_minv_1,Norma_minv_2); 
235       if (background->Integral(Norma_1,Norma_2) == 0)
236         Renorma = 0.;
237       else
238         Renorma = signal->Integral(Norma_1,Norma_2)/background->Integral(Norma_1,Norma_2);
239       difference->Add(background,(-1.)*Renorma); 
240       
241
242       Ntota = signal->Integral(Minv_1,Minv_2);
243       Nback = background->Integral(Minv_1,Minv_2);
244       Norma = ratio->GetFunction("pol0")->GetParameter(0);
245       if (Renorma == 0.)
246         NormaError = 0.;
247       else
248         NormaError =  ratio->GetFunction("pol0")->GetParError(0);
249       printf("Ntotal %f Nback %f Norma %f and NormaError %f \n",Ntota, Nback, Norma, NormaError);
250       printf("differencia is %f \n",difference->Integral(Minv_1,Minv_2));
251       Nmesons[iHistos] = Ntota - Renorma * Nback;
252       NmesonsError[iHistos] = TMath::Sqrt( Ntota + Nback*Renorma*Renorma + Nback*Nback*NormaError*NormaError );  
253       Pt[iHistos] = (iHistos+0.5)*NumberOfPtBins*PtCalibration;
254       PtError[iHistos] = NumberOfPtBins*PtCalibration/2.; 
255       
256     }
257
258   char filenameout[80];
259   sprintf(filenameout,"%s.PtSpectrum_%d_%s_%s",filename, NumberPerPtBin, particle, opt);
260   TFile out(filenameout,"recreate");
261   TGraphErrors * PtSpectrum = new TGraphErrors(NHistos, Pt, Nmesons, PtError, NmesonsError);
262   PtSpectrum->SetName("PtSpectrum");
263   PtSpectrum->Write();
264   out.Close();
265
266   frame->Draw();
267   frame->SetStats(0);
268   frame->SetXTitle("Neutral meson pT (GeV/c)");
269   frame->SetYTitle("Number of neutral mesons per pT bin");
270   PtSpectrum->SetMarkerStyle(27);
271   PtSpectrum->Draw("P");
272
273
274 }