]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSAnalyze.cxx
Macro for checking the serial & bin number of the mounted manus
[u/mrichter/AliRoot.git] / PHOS / AliPHOSAnalyze.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 /* $Id$ */
17
18 //_________________________________________________________________________
19 // Algorythm class to analyze PHOS events. In this class we demostrate, 
20 // how to handle reconstructed objects with AliPHSOIndexToObject.
21 // As an example we propose sulotions for four most frequently used tasks:
22 //    DrawRecon(...) - to draw reconstructed objects in the PHOS plane,
23 //                     very usefull in the debuging
24 //    InvarianMass(...) - to calculate "REAL" and "MIXED" photon pairs 
25 //                        invariant mass distributions
26 //    EnergyResoluition(...) -\ Energy and position resolutions of the 
27 //    PositionResolution(...)-/ reconstructed photons
28 //    Contamination(...) - calculates contamination of the photon spectrum and 
29 //                         pobability of reconstruction of several primaries as 
30 //                         kGAMMA,kELECTRON etc.
31 ////    User Case:
32 //    root [0] AliPHOSAnalyze * a = new AliPHOSAnalyze("galice.root")
33 //                    // set the file you want to analyse
34 //    root [1] a->DrawRecon(1,3)
35 //                    // plot RecObjects, made in event 1, PHOS module 3 
36 //    root [2] a->DrawRecon(1,3,"PHOSRP","another PID")
37 //                    // plot RecObjets made in the event 1, PHOS module 3,
38 //                    // produced in the another reconstruction pass,
39 //                    // which produced PHOS RecParticles ("PHOSRP") with 
40 //                    // title "another PID".
41 //    root [3] a->InvariantMass()
42 //                    // Calculates "REAL" and "MIXED" invariant mass 
43 //                    // distributions of kGAMMA and (kGAMMA+kNEUTRALEM)
44 //                    // and APPENDS this to the file "invmass.root"
45 //    root [4] a->PositionResolution()
46 //                    // calculates two dimentional histos: energy of the primary
47 //                    // photon vs distance betwin incedence point and reconstructed 
48 //                    // poisition. One can analyse the produced file position.root 
49 //                    // with macro PhotonPosition.C
50 //    root [5] a->EnergyResolution()
51 //                    // calculates two dimentional histos: energy of the primary
52 //                    // photon vs energy of the reconstructed particle. One can 
53 //                    // analyse the produced file energy.root 
54 //                    // with macro PhotonEnergy.C
55 //    root [6] a->Contamination()
56 //                    // fills spectra of primary photons and several kinds of 
57 //                    // reconstructed particles, so that analyzing them one can 
58 //                    // estimate conatmination, efficiency of registration etc.
59 //*--
60 //*-- Author: Dmitri Peressounko (SUBATECH & RRC Kurchatov Institute)
61 //////////////////////////////////////////////////////////////////////////////
62
63
64 // --- ROOT system ---
65
66 #include "TFile.h"
67 #include "TH1.h"
68 #include "TH2.h"
69 #include "TH2.h"
70 #include "TParticle.h"
71 #include "TClonesArray.h"
72 #include "TMath.h"
73 #include "TROOT.h"
74
75 // --- Standard library ---
76
77 // --- AliRoot header files ---
78
79 #include "AliLog.h"
80 #include "AliStack.h"
81 #include "AliPHOSGeometry.h"
82 #include "AliPHOSAnalyze.h"
83 #include "AliPHOSDigit.h"
84 #include "AliPHOSSDigitizer.h"
85 #include "AliPHOSEmcRecPoint.h"
86 #include "AliPHOSCpvRecPoint.h"
87 #include "AliPHOSTrackSegment.h"
88 #include "AliPHOSRecParticle.h"
89 #include "AliPHOSLoader.h"
90
91
92 ClassImp(AliPHOSAnalyze)
93
94 //____________________________________________________________________________
95 AliPHOSAnalyze::AliPHOSAnalyze():
96   fCorrection(1.2),  //Value calculated for default parameters of reconstruction
97   fEvt(0),
98   ffileName(),
99   fRunLoader(0)
100 {
101   // default ctor (useless)
102 }
103
104 //____________________________________________________________________________
105 AliPHOSAnalyze::AliPHOSAnalyze(Text_t * fileName):
106   fCorrection(1.05),  //Value calculated for default parameters of reconstruction   
107   fEvt(0),
108   ffileName(fileName),
109   fRunLoader(0)
110 {
111   // ctor: analyze events from root file "name"
112   fRunLoader = AliRunLoader::Open(fileName,"AliPHOSAnalyze");
113   if (fRunLoader == 0x0)
114    {
115      AliError(Form("Error Loading session"));
116    }
117 }
118
119 //____________________________________________________________________________
120 AliPHOSAnalyze::AliPHOSAnalyze(const AliPHOSAnalyze & ana): 
121   TObject(ana),
122   fCorrection(0.),
123   fEvt(0),
124   ffileName(),
125   fRunLoader(0)
126 {
127   // copy ctor
128   ( (AliPHOSAnalyze &)ana ).Copy(*this) ;
129 }
130
131 //____________________________________________________________________________
132 AliPHOSAnalyze::~AliPHOSAnalyze()
133 {
134   // dtor
135
136 }
137 //____________________________________________________________________________
138 void AliPHOSAnalyze::DrawRecon(Int_t Nevent,Int_t Nmod){
139   //Draws pimary particles and reconstructed 
140   //digits, RecPoints, RecPartices etc 
141   //for event Nevent in the module Nmod.
142
143   //========== Create ObjectLoader
144   if (fRunLoader == 0x0)
145    {
146      AliError(Form("Error Loading session"));
147      return;
148    }
149   
150   AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(fRunLoader->GetLoader("PHOSLoader"));
151   if ( gime == 0 ) 
152    {
153      AliError(Form("Could not obtain the Loader object !")); 
154      return ;
155    } 
156   
157   
158   if(Nevent >= fRunLoader->GetNumberOfEvents() ) {
159     AliError(Form("There is no event %d only %d events available", Nevent, fRunLoader->GetNumberOfEvents() )) ;
160     return ;
161   }
162   AliPHOSGeometry * phosgeom =  AliPHOSGeometry::GetInstance() ;
163   fRunLoader->GetEvent(Nevent);
164
165   Int_t nx = phosgeom->GetNPhi() ;
166   Int_t nz = phosgeom->GetNZ() ;
167   Float_t * cri= phosgeom->GetEMCAGeometry()->GetCrystalHalfSize() ;
168   Float_t x = nx*cri[0] ;
169   Float_t z = nz*cri[2] ;
170   Int_t nxCPV = (Int_t) (nx*phosgeom->GetPadSizePhi()/(2.*cri[0])) ;
171   Int_t nzCPV = (Int_t) (nz*phosgeom->GetPadSizeZ()/(2.*cri[2])) ;
172   
173   TH2F * emcDigits = (TH2F*) gROOT->FindObject("emcDigits") ;
174   if(emcDigits)
175     emcDigits->Delete() ;
176   emcDigits = new TH2F("emcDigits","EMC digits",  nx,-x,x,nz,-z,z);
177   TH2F * emcSdigits =(TH2F*) gROOT->FindObject("emcSdigits") ;  
178   if(emcSdigits)
179     emcSdigits->Delete() ;
180   emcSdigits = new TH2F("emcSdigits","EMC sdigits", nx,-x,x,nz,-z,z);
181   TH2F * emcRecPoints = (TH2F*)gROOT->FindObject("emcRecPoints") ; 
182   if(emcRecPoints)
183     emcRecPoints->Delete() ;
184   emcRecPoints = new TH2F("emcRecPoints","EMC RecPoints",nx,-x,x,nz,-z,z);
185   TH2F * cpvSdigits =(TH2F*) gROOT->FindObject("cpvSdigits") ;
186   if(cpvSdigits)
187     cpvSdigits->Delete() ;
188   cpvSdigits = new TH2F("cpvSdigits","CPV sdigits", nx,-x,x,nz,-z,z);
189   TH2F * cpvDigits = (TH2F*)gROOT->FindObject("cpvDigits") ;
190   if(cpvDigits)
191     cpvDigits->Delete() ;
192   cpvDigits = new TH2F("cpvDigits","CPV digits",   nxCPV,-x,x,nzCPV,-z,z) ;
193   TH2F * cpvRecPoints= (TH2F*)gROOT->FindObject("cpvRecPoints") ; 
194   if(cpvRecPoints)
195     cpvRecPoints->Delete() ;
196   cpvRecPoints = new TH2F("cpvRecPoints","CPV RecPoints",    nxCPV,-x,x,nzCPV,-z,z) ;
197
198   TH2F * phot = (TH2F*)gROOT->FindObject("phot") ;
199   if(phot)
200     phot->Delete() ;
201   phot = new TH2F("phot","Primary Photon",  nx,-x,x,nz,-z,z);
202   TH2F * recPhot = (TH2F*)gROOT->FindObject("recPhot") ; 
203   if(recPhot)
204     recPhot->Delete() ;
205   recPhot = new TH2F("recPhot","RecParticles with primary Photon",nx,-x,x,nz,-z,z);
206   
207   //Get Vertex
208   Double_t vtx[3]={0.,0.,0.} ;  
209 //DP: extract vertex either from Generator or from data
210
211   
212   //Plot Primary Particles
213   
214   if (fRunLoader->Stack() == 0x0) fRunLoader->LoadKinematics("READ");
215   
216
217   const TParticle * primary ;
218   Int_t iPrimary ;
219   for ( iPrimary = 0 ; iPrimary < fRunLoader->Stack()->GetNprimary() ; iPrimary++)
220     {
221       primary = fRunLoader->Stack()->Particle(iPrimary);
222       
223       Int_t primaryType = primary->GetPdgCode();
224 //       if( (primaryType == 211)||(primaryType == -211)||(primaryType == 2212)||(primaryType == -2212)
225 //          ||(primaryType == 11)||(primaryType == -11) ) {
226 //         Int_t moduleNumber ;
227 //         Double_t primX, primZ ;
228 //         phosgeom->ImpactOnEmc(primary->Theta(), primary->Phi(), moduleNumber, primX, primZ) ;
229 //         if(moduleNumber==Nmod)
230 //           charg->Fill(primZ,primX,primary->Energy()) ;
231 //       }
232       if( primaryType == 22 ) {
233         Int_t moduleNumber ;
234         Double_t primX, primZ ;
235         phosgeom->ImpactOnEmc(vtx,primary->Theta(), primary->Phi(), moduleNumber, primX, primZ) ;
236         if(moduleNumber==Nmod) 
237           phot->Fill(primZ,primX,primary->Energy()) ;
238       }
239 //       else{
240 //         if( primaryType == -2112 ) {
241 //           Int_t moduleNumber ;
242 //           Double_t primX, primZ ;
243 //           phosgeom->ImpactOnEmc(primary->Theta(), primary->Phi(), moduleNumber, primX, primZ) ;
244 //           if(moduleNumber==Nmod)
245 //             nbar->Fill(primZ,primX,primary->Energy()) ;
246 //         }
247 //       }
248     }  
249
250   
251   Int_t iSDigit ;
252   AliPHOSDigit * sdigit ;
253   const TClonesArray * sdigits = gime->SDigits() ;
254   Int_t nsdig[5] = {0,0,0,0,0} ;
255   if(sdigits){
256     for(iSDigit = 0; iSDigit < sdigits->GetEntriesFast() ; iSDigit++)
257       {
258        sdigit = (AliPHOSDigit *) sdigits->At(iSDigit) ;
259        Int_t relid[4];
260        phosgeom->AbsToRelNumbering(sdigit->GetId(), relid) ;
261        Float_t x,z ;
262        phosgeom->RelPosInModule(relid,x,z);
263        Float_t e = sdigit->GetEnergy() ;
264        nsdig[relid[0]-1]++ ;
265        if(relid[0]==Nmod){
266          if(relid[1]==0)  //EMC
267            emcSdigits->Fill(x,z,e) ;
268          if( relid[1]!=0 )
269            cpvSdigits->Fill(x,z,e) ;
270        }
271       }
272   }
273   TString message ; 
274   message  = "Number of EMC + CPV SDigits per module: \n" ;
275   message += "%d %d %d %d %d\n"; 
276   AliInfo(Form(message.Data(), nsdig[0], nsdig[1], nsdig[2], nsdig[3], nsdig[4] )) ;
277
278   //Plot digits
279   Int_t iDigit ;
280   AliPHOSDigit * digit ;
281   const TClonesArray * digits = gime->Digits(); 
282   if(digits) {
283     for(iDigit = 0; iDigit < digits->GetEntriesFast(); iDigit++)
284       {
285        digit = (AliPHOSDigit *) digits->At(iDigit) ;
286        Int_t relid[4];
287        phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
288        Float_t x,z ;
289        phosgeom->RelPosInModule(relid,x,z) ;
290        Float_t e = digit->GetEnergy() ;
291        if(relid[0]==Nmod){
292          if(relid[1]==0)  //EMC
293            emcDigits->Fill(x,z,e) ;
294          if( relid[1]!=0 )
295            cpvDigits->Fill(x,z,e) ;
296        }
297       }
298   }
299   
300   
301   //Plot RecPoints
302   Int_t irecp ;
303   TVector3 pos ;
304   TObjArray * emcrp = gime->EmcRecPoints() ;
305   if(emcrp) {
306     for(irecp = 0; irecp < emcrp->GetEntriesFast() ; irecp ++){
307       AliPHOSEmcRecPoint * emc = (AliPHOSEmcRecPoint *) emcrp->At(irecp) ;
308       if(emc->GetPHOSMod()==Nmod){
309        emc->GetLocalPosition(pos) ;
310        emcRecPoints->Fill(pos.X(),pos.Z(),emc->GetEnergy());
311       }
312     }
313   }
314   
315   TObjArray * cpvrp = gime->CpvRecPoints() ;
316   if(cpvrp) {
317     for(irecp = 0; irecp < cpvrp->GetEntriesFast() ; irecp ++){
318       AliPHOSRecPoint * cpv = (AliPHOSCpvRecPoint *) cpvrp->At(irecp) ;
319       if(cpv->GetPHOSMod()==Nmod){
320        cpv->GetLocalPosition(pos) ;
321        cpvRecPoints->Fill(pos.X(),pos.Z(),cpv->GetEnergy());
322       }
323     }
324   }
325     
326   //Plot RecParticles
327   AliPHOSRecParticle * recParticle ;
328   Int_t iRecParticle ;
329   TClonesArray * rp = gime->RecParticles() ;
330   TClonesArray * ts = gime->TrackSegments() ;
331   if(rp && ts && emcrp) {
332     for(iRecParticle = 0; iRecParticle < rp->GetEntriesFast() ; iRecParticle++ )
333       {
334        recParticle = (AliPHOSRecParticle *) rp->At(iRecParticle) ;
335        Int_t moduleNumberRec ;
336        Double_t recX, recZ ;
337        phosgeom->ImpactOnEmc(vtx,recParticle->Theta(), recParticle->Phi(), moduleNumberRec, recX, recZ) ;
338        if(moduleNumberRec == Nmod){
339          
340          Double_t minDistance = 5. ;
341          Int_t closestPrimary = -1 ;       
342
343          //extract list of primaries: it is stored at EMC RecPoints
344          Int_t emcIndex = ((AliPHOSTrackSegment *) ts->At(recParticle->GetPHOSTSIndex()))->GetEmcIndex() ;
345          Int_t numberofprimaries ;
346          Int_t * listofprimaries  = ((AliPHOSRecPoint*) emcrp->At(emcIndex))->GetPrimaries(numberofprimaries)  ;
347          Int_t index ;
348          const TParticle * primary ;
349          Double_t distance = minDistance ;
350          
351          for ( index = 0 ; index < numberofprimaries ; index++){
352            primary = fRunLoader->Stack()->Particle(listofprimaries[index]) ;
353            Int_t moduleNumber ;
354            Double_t primX, primZ ;
355            phosgeom->ImpactOnEmc(vtx,primary->Theta(), primary->Phi(), moduleNumber, primX, primZ) ;
356            if(moduleNumberRec == moduleNumber)
357              distance = TMath::Sqrt((recX-primX)*(recX-primX)+(recZ-primZ)*(recZ-primZ) ) ;
358            if(minDistance > distance)
359              {
360               minDistance = distance ;
361               closestPrimary = listofprimaries[index] ;
362              }
363          }
364          
365          if(closestPrimary >=0 ){
366            
367            Int_t primaryType = fRunLoader->Stack()->Particle(closestPrimary)->GetPdgCode() ;
368            
369            if(primaryType==22)
370              recPhot->Fill(recZ,recX,recParticle->Energy()) ;
371 //            else
372 //              if(primaryType==-2112)
373 //               recNbar->Fill(recZ,recX,recParticle->Energy()) ; 
374          }
375        }
376       }
377
378   }
379   
380   //Plot made histograms
381   emcSdigits->Draw("box") ;
382   emcDigits->SetLineColor(5) ;
383   emcDigits->Draw("boxsame") ;
384   emcRecPoints->SetLineColor(2) ;
385   emcRecPoints->Draw("boxsame") ;
386   cpvSdigits->SetLineColor(1) ;
387   cpvSdigits->Draw("boxsame") ;
388   
389 }
390 //____________________________________________________________________________
391 void AliPHOSAnalyze::Ls(){
392   //lists branches and titles of PHOS-related branches of TreeR, TreeD, TreeS
393   
394   if (fRunLoader == 0x0)
395    {
396      AliError(Form("Error Loading session"));
397      return;
398    }
399   
400   AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(fRunLoader->GetLoader("PHOSLoader"));
401   if ( gime == 0 ) 
402    {
403      AliError(Form("Could not obtain the Loader object !")); 
404      return ;
405    } 
406
407
408   Int_t ibranch;
409   TObjArray * branches; 
410   
411   if (gime->TreeS() == 0x0) 
412    {
413      if (gime->LoadSDigits("READ"))
414       {
415         AliError(Form("Problems with loading summable digits"));
416         return;
417       }
418    }
419   branches = gime->TreeS()->GetListOfBranches() ;
420  
421   TString message ; 
422   message  = "TreeS:\n" ;
423   for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
424     TBranch * branch=(TBranch *) branches->At(ibranch) ;
425     if(strstr(branch->GetName(),"PHOS") ){
426       message += "       " ; 
427       message += branch->GetName() ; 
428       message += "     " ; 
429       message += branch->GetTitle() ;
430       message += "\n" ; 
431     }
432   }
433   if (gime->TreeD() == 0x0) 
434    {
435      if (gime->LoadDigits("READ"))
436       {
437         AliError(Form("Problems with loading digits"));
438         return;
439       }
440    }
441
442   branches = gime->TreeD()->GetListOfBranches() ;
443   
444   message += "TreeD:\n" ;
445   for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
446     TBranch * branch=(TBranch *) branches->At(ibranch) ;
447     if(strstr(branch->GetName(),"PHOS") ) {
448       message += "       "; 
449       message += branch->GetName() ; 
450       message += "     " ; 
451       message += branch->GetTitle() ; 
452       message +="\n" ;
453     }
454   }
455   
456   if (gime->TreeR() == 0x0) 
457    {
458      if (gime->LoadRecPoints("READ"))
459       {
460         AliError(Form("Problems with loading rec points"));
461         return;
462       }
463    }
464
465   branches = gime->TreeR()->GetListOfBranches() ;
466   
467   message += "TreeR: \n" ;
468   for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
469     TBranch * branch=(TBranch *) branches->At(ibranch) ;
470     if(strstr(branch->GetName(),"PHOS") ) {
471       message += "       " ; 
472       message += branch->GetName() ; 
473       message += "     " ;
474       message += branch->GetTitle() ; 
475       message += "\n" ;
476     }
477   }
478   AliInfo(Form(message.Data())) ;  
479 }
480 //____________________________________________________________________________
481  void AliPHOSAnalyze::InvariantMass()
482 {
483   // Calculates Real and Mixed invariant mass distributions
484   if (fRunLoader == 0x0)
485    {
486      AliError(Form("Error Loading session"));
487      return;
488    }
489   
490   AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(fRunLoader->GetLoader("PHOSLoader"));
491   if ( gime == 0 ) 
492    {
493      AliError(Form("Could not obtain the Loader object !")); 
494      return ;
495    } 
496   
497   gime->LoadRecParticles("READ");
498   
499   Int_t nMixedEvents = 4 ; //# of events used for calculation of 'mixed' distribution 
500   
501   
502   //opening file
503   TFile * mfile = new TFile("invmass.root","update");
504   
505   //========== Reading /Booking Histograms
506   TH2D * hRealEM = 0 ;
507   hRealEM = (TH2D*) mfile->Get("hRealEM") ;
508   if(hRealEM == 0) 
509     hRealEM = new TH2D("hRealEM",   "Real for EM particles",      250,0.,1.,40,0.,4.) ;
510   TH2D * hRealPhot = 0 ;
511
512   hRealPhot = (TH2D*)mfile->Get("hRealPhot");
513   if(hRealPhot == 0)
514     hRealPhot = new TH2D("hRealPhot", "Real for kPhoton particles", 250,0.,1.,40,0.,4.) ;
515
516   TH2D * hMixedEM = 0 ;
517   hMixedEM = (TH2D*) mfile->Get("hMixedEM") ;
518   if(hMixedEM == 0)
519     hMixedEM = new TH2D("hMixedEM",  "Mixed for EM particles",     250,0.,1.,40,0.,4.) ;
520
521   TH2D * hMixedPhot = 0 ;
522   hMixedPhot = (TH2D*) mfile->Get("hMixedPhot") ;
523   if(hMixedPhot == 0)
524     hMixedPhot = new TH2D("hMixedPhot","Mixed for kPhoton particles",250,0.,1.,40,0.,4.) ;
525   
526
527   //reading event and copyng it to TConesArray of all photons
528
529   TClonesArray * allRecParticleList  = new TClonesArray("AliPHOSRecParticle", 1000) ;
530   Int_t * nRecParticles = new Int_t[nMixedEvents] ; // to mark boundaries of each event in the total list
531   for(Int_t index = 0; index < nMixedEvents; index ++)
532     nRecParticles[index] = 0 ;
533   Int_t iRecPhot = 0 ;                // number of EM particles in total list
534   
535   //scan over all events
536   Int_t event ;
537   
538
539   if (fRunLoader->TreeE() == 0x0) fRunLoader->LoadHeader();
540   
541   
542   Int_t maxevent = (Int_t)fRunLoader->TreeE()->GetEntries();
543   //  for(event = 0; event < gime->MaxEvent(); event++  ){
544   
545   
546   
547   for(event = 0; event < maxevent; event++  ){
548     fRunLoader->GetEvent(event);  //will read only TreeR 
549     
550     //copy EM RecParticles to the "total" list        
551     const AliPHOSRecParticle * recParticle ;
552     Int_t iRecParticle ;
553     TClonesArray * rp = gime->RecParticles() ;
554     if(!rp){
555       AliError(Form("Can't find RecParticles")) ; 
556       return ;
557     }
558
559     for(iRecParticle = 0; iRecParticle < rp->GetEntriesFast(); iRecParticle++ )
560       {
561        recParticle = (AliPHOSRecParticle *) rp->At(iRecParticle) ;
562        if((recParticle->GetType() == AliPHOSFastRecParticle::kNEUTRALEMFAST)||
563           (recParticle->GetType() == AliPHOSFastRecParticle::kNEUTRALEMSLOW))
564          new( (*allRecParticleList)[iRecPhot++] ) AliPHOSRecParticle(*recParticle) ;
565       }
566     
567     Int_t mevent = event%nMixedEvents ; //event number in the "mixed" cicle
568     nRecParticles[mevent] = iRecPhot-1 ;  
569     
570     //check, if it is time to calculate invariant mass?
571     Int_t maxevent = (Int_t)gAlice->TreeE()->GetEntries() ; 
572     if((mevent == 0) && (event +1 == maxevent)){
573       
574       //   if((mevent == 0) && (event +1 == gime->MaxEvent())){
575       
576       //calculate invariant mass:
577       Int_t irp1,irp2 ;
578       Int_t nCurEvent = 0 ;
579       
580       for(irp1 = 0; irp1 < allRecParticleList->GetEntries()-1; irp1++){
581        AliPHOSRecParticle * rp1 = (AliPHOSRecParticle *)allRecParticleList->At(irp1) ;
582        
583        for(irp2 = irp1+1; irp2 < allRecParticleList->GetEntries(); irp2++){
584          AliPHOSRecParticle * rp2 = (AliPHOSRecParticle *)allRecParticleList->At(irp2) ;
585          
586          Double_t invMass ;
587          invMass = (rp1->Energy()+rp2->Energy())*(rp1->Energy()+rp2->Energy())-
588            (rp1->Px()+rp2->Px())*(rp1->Px()+rp2->Px())-
589            (rp1->Py()+rp2->Py())*(rp1->Py()+rp2->Py())-
590            (rp1->Pz()+rp2->Pz())*(rp1->Pz()+rp2->Pz()) ;
591          
592          if(invMass> 0)
593            invMass = TMath::Sqrt(invMass);
594          
595          Double_t pt ; 
596          pt = TMath::Sqrt((rp1->Px()+rp2->Px() )*( rp1->Px()+rp2->Px() ) + 
597                         (rp1->Py()+rp2->Py() )*( rp1->Py()+rp2->Py() ) );
598          
599          if(irp1 > nRecParticles[nCurEvent])
600            nCurEvent++;
601          
602          if(irp2 <= nRecParticles[nCurEvent]){ //'Real' event
603            hRealEM->Fill(invMass,pt);
604            if((rp1->GetType() == AliPHOSFastRecParticle::kNEUTRALEMFAST)&&
605               (rp2->GetType() == AliPHOSFastRecParticle::kNEUTRALEMFAST) )
606              hRealPhot->Fill(invMass,pt);
607          }
608          else{
609            hMixedEM->Fill(invMass,pt);
610            if((rp1->GetType() == AliPHOSFastRecParticle::kNEUTRALEMFAST)&&
611               (rp2->GetType() == AliPHOSFastRecParticle::kNEUTRALEMFAST) )
612              hMixedPhot->Fill(invMass,pt);
613          } //real-mixed
614          
615       } //loop over second rp
616       }//loop over first rp
617       
618       //Make some cleanings 
619       for(Int_t index = 0; index < nMixedEvents; index ++)
620        nRecParticles[index] = 0 ;
621       iRecPhot = 0 ;              
622       allRecParticleList->Clear() ;
623       
624     }
625   }
626   delete allRecParticleList ;
627   
628   //writing output
629   mfile->cd();
630   
631   hRealEM->Write(0,kOverwrite) ;
632   hRealPhot->Write(0,kOverwrite) ;
633   hMixedEM->Write(0,kOverwrite) ;
634   hMixedPhot->Write(0,kOverwrite) ;
635   
636   mfile->Write();
637   mfile->Close();
638   delete mfile ;
639   delete nRecParticles;
640
641 }
642
643 //____________________________________________________________________________
644  void AliPHOSAnalyze::EnergyResolution()
645 {
646   //fills two dimentional histo: energy of primary vs. energy of reconstructed
647
648   TH2F * hAllEnergy = 0 ;  //all reconstructed with primary photon   
649   TH2F * hPhotEnergy= 0 ;  //kGamma  with primary photon   
650   TH2F * hEMEnergy  = 0 ;  //electromagnetic with primary photon   
651
652   //opening file and reading histograms if any
653   TFile * efile = new TFile("energy.root","update");
654
655   hAllEnergy = (TH2F*)efile->Get("hAllEnergy") ;
656   if(hAllEnergy == 0)
657     hAllEnergy  = new TH2F("hAllEnergy",  "Energy of any RP with primary photon",100, 0., 5., 100, 0., 5.);
658
659   hPhotEnergy =(TH2F*) efile->Get("hPhotEnergy") ;
660   if(hPhotEnergy == 0)
661     hPhotEnergy = new TH2F("hPhotEnergy", "Energy of kGAMMA with primary photon",100, 0., 5., 100, 0., 5.);
662
663   hEMEnergy =(TH2F*) efile->Get("hEMEnergy");
664   if(hEMEnergy == 0)
665     hEMEnergy   = new TH2F("hEMEnergy",   "Energy of EM with primary photon",    100, 0., 5., 100, 0., 5.);
666
667
668   if (fRunLoader == 0x0)
669    {
670      AliError(Form("Error Loading session"));
671      return;
672    }
673   
674   AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(fRunLoader->GetLoader("PHOSLoader"));
675   if ( gime == 0 ) 
676    {
677      AliError(Form("Could not obtain the Loader object !")); 
678      return ;
679    } 
680
681
682   AliPHOSGeometry * phosgeom =  AliPHOSGeometry::GetInstance() ;
683
684   Int_t ievent;
685   Int_t maxevent = (Int_t)fRunLoader->TreeE()->GetEntries();
686
687   fRunLoader->LoadKinematics("READ");
688   gime->LoadTracks("READ");
689   
690   for ( ievent=0; ievent < maxevent ; ievent++){
691
692     //read the current event
693     fRunLoader->GetEvent(ievent) ;
694
695     Double_t vtx[3]={0.,0.,0.} ;  
696
697     const AliPHOSRecParticle * recParticle ;
698     Int_t iRecParticle ;
699     TClonesArray * rp = gime->RecParticles() ;
700     if(!rp) {
701       AliError(Form("Event %d,  Can't find RecParticles ", ievent)) ;  
702       return ;
703     }
704     TClonesArray * ts = gime->TrackSegments() ;
705     if(!ts) {
706       AliError(Form("Event %d,  Can't find TrackSegments", ievent)) ;  
707       return ;
708     }
709     TObjArray * emcrp = gime->EmcRecPoints() ;
710     if(!emcrp){
711       AliError(Form("Event %d,  Can't find EmcRecPoints")) ; 
712       return ;
713     }
714       
715     for(iRecParticle = 0; iRecParticle < rp->GetEntriesFast() ;iRecParticle++ ){
716       recParticle = (AliPHOSRecParticle *) rp->At(iRecParticle) ;
717       
718       //find the closest primary
719       Int_t moduleNumberRec ;
720       Double_t recX, recZ ;
721       phosgeom->ImpactOnEmc(vtx,recParticle->Theta(), recParticle->Phi(), moduleNumberRec, recX, recZ) ;
722       
723       Double_t minDistance  = 100. ;
724       Int_t closestPrimary = -1 ;
725       
726       //extract list of primaries: it is stored at EMC RecPoints
727       Int_t emcIndex = ((AliPHOSTrackSegment*) ts->At(recParticle->GetPHOSTSIndex()))->GetEmcIndex() ;
728       Int_t numberofprimaries ;
729       Int_t * listofprimaries  = ((AliPHOSEmcRecPoint*) emcrp->At(emcIndex))->GetPrimaries(numberofprimaries)  ;
730       
731       Int_t index ;
732       const TParticle * primary ;
733       Double_t distance = minDistance ;
734       Double_t dX, dZ; 
735       Double_t dXmin = 0.; 
736       Double_t dZmin = 0. ;
737       for ( index = 0 ; index < numberofprimaries ; index++){
738
739        primary = fRunLoader->Stack()->Particle(listofprimaries[index]) ;
740
741        Int_t moduleNumber ;
742        Double_t primX, primZ ;
743        phosgeom->ImpactOnEmc(vtx,primary->Theta(), primary->Phi(), moduleNumber, primX, primZ) ;
744        if(moduleNumberRec == moduleNumber) {
745          dX = recX - primX;
746          dZ = recZ - primZ;
747          distance = TMath::Sqrt(dX*dX + dZ*dZ) ;
748          if(minDistance > distance) {
749            minDistance = distance ;
750            dXmin = dX;
751            dZmin = dZ;
752            closestPrimary = listofprimaries[index] ;
753          }
754        }
755       }
756
757       //if found primary, fill histograms
758       if(closestPrimary >=0 ){
759        const TParticle * primary = fRunLoader->Stack()->Particle(closestPrimary) ;
760        if(primary->GetPdgCode() == 22){
761          hAllEnergy->Fill(primary->Energy(), recParticle->Energy()) ;
762          if(recParticle->GetType() == AliPHOSFastRecParticle::kNEUTRALEMFAST){
763            hPhotEnergy->Fill(primary->Energy(), recParticle->Energy() ) ; 
764            hEMEnergy->Fill(primary->Energy(), recParticle->Energy() ) ; 
765          }
766          else
767            if(recParticle->GetType() == AliPHOSFastRecParticle::kNEUTRALEMSLOW)
768              hEMEnergy->Fill(primary->Energy(), recParticle->Energy() ) ; 
769        }
770       }
771     }
772   }
773
774   //write filled histograms
775   efile->cd() ;
776   hAllEnergy->Write(0,kOverwrite) ;
777   hPhotEnergy->Write(0,kOverwrite) ;
778   hEMEnergy->Write(0,kOverwrite)  ;
779   //  efile->Write() ;
780   efile->Close() ;
781   delete efile ;
782
783 }
784 //____________________________________________________________________________
785 void AliPHOSAnalyze::PositionResolution()
786 {
787   //fills two dimentional histo: energy vs. primary - reconstructed distance  
788
789
790
791   TH2F * hAllPosition  = 0;     // Position of any RP with primary photon
792   TH2F * hPhotPosition = 0;    // Position of kGAMMA with primary photon
793   TH2F * hEMPosition   = 0;      // Position of EM with primary photon
794
795   TH1F * hAllPositionX = 0;    // X-Position Resolution of photons with photon primary
796   TH1F * hAllPositionZ = 0;    // Z-Position Resolution of photons with photon primary
797
798
799   //opening file and reading histograms if any
800   TFile * pfile = new TFile("position.root","update");
801
802   hAllPosition = (TH2F*)pfile->Get("hAllPosition");
803   if(hAllPosition == 0)
804     hAllPosition  = new TH2F("hAllPosition",  
805                           "Position of any RP with primary photon",100, 0., 5., 100, 0., 5.);
806   hPhotPosition= (TH2F*)pfile->Get("hPhotPosition");
807   if(hPhotPosition == 0)
808     hPhotPosition = new TH2F("hPhotPosition", 
809                           "Position of kGAMMA with primary photon",100, 0., 5., 100, 0., 5.);
810   hEMPosition= (TH2F*)pfile->Get("hEMPosition") ;
811   if(hEMPosition == 0)
812     hEMPosition   = new TH2F("hEMPosition",   
813                           "Position of EM with primary photon",    100, 0., 5., 100, 0., 5.);
814   hAllPositionX = (TH1F*)pfile->Get("hAllPositionX") ;                        
815   if(hAllPositionX == 0)
816     hAllPositionX = new TH1F("hAllPositionX", 
817                           "Delta X of any RP with primary photon",100, -2., 2.);
818   hAllPositionZ =(TH1F*) pfile->Get("hAllPositionZ") ;
819   if(hAllPositionZ == 0)
820     hAllPositionZ = new TH1F("hAllPositionZ", 
821                           "Delta X of any RP with primary photon",100, -2., 2.);
822
823   if (fRunLoader == 0x0)
824    {
825      AliError(Form("Error Loading session"));
826      return;
827    }
828   
829   AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(fRunLoader->GetLoader("PHOSLoader"));
830   if ( gime == 0 ) 
831    {
832      AliError(Form("Could not obtain the Loader object !")); 
833      return ;
834    } 
835   
836   if (fRunLoader->TreeE() == 0x0) fRunLoader->LoadHeader();
837
838   AliPHOSGeometry * phosgeom =  AliPHOSGeometry::GetInstance() ;
839
840   Int_t ievent;
841   Int_t maxevent = (Int_t)fRunLoader->TreeE()->GetEntries() ; 
842   for ( ievent=0; ievent < maxevent ; ievent++){
843     
844     //read the current event
845     fRunLoader->GetEvent(ievent) ;
846
847     //DP:Extract vertex position
848     Double_t vtx[3]={0.,0.,0.} ;  
849
850     TClonesArray * rp = gime->RecParticles() ;
851     if(!rp) {
852       AliError(Form("Event %d,  Can't find RecParticles", ievent)) ;
853       return ;
854     }
855     TClonesArray * ts = gime->TrackSegments() ;
856     if(!ts) {
857       AliError(Form("Event %d,  Can't find TrackSegments", ievent)) ;
858       return ;
859     }
860     TObjArray * emcrp = gime->EmcRecPoints() ;
861     if(!emcrp){
862       AliError(Form("Event %d,  Can't find EmcRecPoints", ievent)) ;
863       return ;
864     }
865     
866  
867     const AliPHOSRecParticle * recParticle ;
868     Int_t iRecParticle ;
869     for(iRecParticle = 0; iRecParticle < rp->GetEntriesFast(); iRecParticle++ ){
870       recParticle = (AliPHOSRecParticle *) rp->At(iRecParticle) ;
871       
872       //find the closest primary
873       Int_t moduleNumberRec ;
874       Double_t recX, recZ ;
875       phosgeom->ImpactOnEmc(vtx,recParticle->Theta(), recParticle->Phi(), moduleNumberRec, recX, recZ) ;
876       
877       Double_t minDistance  = 100. ;
878       Int_t closestPrimary = -1 ;
879       
880       //extract list of primaries: it is stored at EMC RecPoints
881       Int_t emcIndex = ((AliPHOSTrackSegment*) ts->At(recParticle->GetPHOSTSIndex()))->GetEmcIndex() ;
882       Int_t numberofprimaries ;
883       Int_t * listofprimaries  = ((AliPHOSEmcRecPoint *) emcrp->At(emcIndex))->GetPrimaries(numberofprimaries)  ;
884
885       Int_t index ;
886       const TParticle * primary ;
887       Double_t distance = minDistance ;
888       Double_t dX = 1000; // incredible number
889       Double_t dZ = 1000; // for the case if no primary will be found
890       Double_t dXmin = 0.; 
891       Double_t dZmin = 0. ;
892       for ( index = 0 ; index < numberofprimaries ; index++){
893        primary = fRunLoader->Stack()->Particle(listofprimaries[index]) ;
894        Int_t moduleNumber ;
895        Double_t primX, primZ ;
896        phosgeom->ImpactOnEmc(vtx,primary->Theta(), primary->Phi(), moduleNumber, primX, primZ) ;
897        if(moduleNumberRec == moduleNumber) {
898          dX = recX - primX;
899          dZ = recZ - primZ;
900          distance = TMath::Sqrt(dX*dX + dZ*dZ) ;
901          if(minDistance > distance) {
902            minDistance = distance ;
903            dXmin = dX;
904            dZmin = dZ;
905            closestPrimary = listofprimaries[index] ;
906          }
907        }
908       }
909       
910       //if found primary, fill histograms
911       if(closestPrimary >=0 ){
912        const TParticle * primary = fRunLoader->Stack()->Particle(closestPrimary) ;
913        if(primary->GetPdgCode() == 22){
914          hAllPosition->Fill(primary->Energy(), minDistance) ;
915          hAllPositionX->Fill(primary->Energy(), dX) ;
916          hAllPositionZ->Fill(primary->Energy(), dZ) ;
917          if(recParticle->GetType() == AliPHOSFastRecParticle::kNEUTRALEMFAST){
918            hPhotPosition->Fill(primary->Energy(), minDistance ) ; 
919            hEMPosition->Fill(primary->Energy(), minDistance ) ; 
920          }
921          else
922            if(recParticle->GetType() == AliPHOSFastRecParticle::kNEUTRALEMSLOW)
923              hEMPosition->Fill(primary->Energy(), minDistance ) ; 
924        }
925       }
926     }
927   }
928   
929   //Write output histgrams
930   pfile->cd() ;
931   hAllPosition->Write(0,kOverwrite) ;
932   hAllPositionX->Write(0,kOverwrite) ;
933   hAllPositionZ->Write(0,kOverwrite) ;
934   hPhotPosition->Write(0,kOverwrite) ;
935   hEMPosition->Write(0,kOverwrite) ;
936   pfile->Write() ;
937   pfile->Close() ;
938   delete pfile ;
939
940
941 }
942 //____________________________________________________________________________
943 void AliPHOSAnalyze::Contamination(){
944 // fills spectra of primary photons and several kinds of 
945 // reconstructed particles, so that analyzing them one can 
946 // estimate conatmination, efficiency of registration etc.
947
948   //define several general histograms
949   TH1F * hPrimary = 0;   //spectrum (P_t distribution) of primary photons         
950   TH1F * hAllRP   = 0;   //spectrum of all RecParticles in PHOS
951   TH1F * hPhot    = 0;   //spectrum of kGAMMA RecParticles
952   TH1F * hShape   = 0;   //spectrum of all EM RecParticles
953   TH1F * hVeto    = 0;   //spectrum of all neutral RecParticles
954
955   //Now separate histograms in accoradance with primary
956   //primary - photon
957   TH1F * hPhotReg = 0;   //Registeres as photon
958   TH1F * hPhotEM  = 0;   //Registered as EM       
959
960   //primary - n
961   TH1F * hNReg = 0;   //Registeres as photon          
962   TH1F * hNEM  = 0;   //Registered as EM            
963
964   //primary - nBar
965   TH1F * hNBarReg = 0;   //Registeres as photon
966   TH1F * hNBarEM  = 0;   //Registered as EM          
967
968   //primary - charged hadron (pBar excluded)
969   TH1F * hChargedReg = 0;   //Registeres as photon  
970   TH1F * hChargedEM  = 0;   //Registered as EM           
971
972   //primary - pBar
973   TH1F * hPbarReg = 0;   //Registeres as photon  
974   TH1F * hPbarEM  = 0;   //Registered as EM 
975
976
977   //Reading histograms from the file
978   TFile * cfile = new TFile("contamination.root","update") ;
979
980   //read general histograms
981   hPrimary = (TH1F*) cfile->Get("hPrimary") ;
982   if(hPrimary == 0)
983     hPrimary= new TH1F("hPrimary", "Primary photon spectrum", 100, 0., 5.);
984   hAllRP = (TH1F*)cfile->Get("hAllRP") ;
985   if(hAllRP == 0)
986     hAllRP = new TH1F("hAllRP","All Reconstructed particles", 100, 0., 5.);
987   hPhot  = (TH1F*)cfile->Get("hPhot") ;
988   if(hPhot == 0)
989     hPhot = new TH1F("hPhot","All kGAMMA RecParticles",100, 0., 5.);
990   hShape = (TH1F*) cfile->Get("hShape") ;
991   if(hShape == 0)
992     hShape = new TH1F("hShape","All particles with EM shower",100, 0., 5.);
993   hVeto= (TH1F*)cfile->Get("hVeto") ;
994   if(hVeto == 0) 
995     hVeto  = new TH1F("hVeto", "All uncharged particles",      100, 0., 5.);
996
997
998   //primary - photon
999   hPhotReg = (TH1F*)cfile->Get("hPhotReg");
1000   if(hPhotReg == 0)
1001     hPhotReg   = new TH1F("hPhotReg","Photon registered as photon",100, 0., 5.);
1002   hPhotEM  =(TH1F*)cfile->Get("hPhotEM");
1003   if(hPhotEM== 0)
1004     hPhotEM   = new TH1F("hPhotEM",  "Photon registered as EM", 100, 0., 5.);
1005
1006   //primary - n
1007   hNReg = (TH1F*)cfile->Get("hNReg");
1008   if(hNReg== 0)
1009    hNReg      = new TH1F("hNReg",   "N registered as photon",              100, 0., 5.);
1010   hNEM  = (TH1F*)cfile->Get("hNEM"); 
1011   if(hNEM== 0)
1012     hNEM      = new TH1F("hNEM",    "N registered as EM",      100, 0., 5.);
1013
1014   //primary - nBar
1015   hNBarReg =(TH1F*)cfile->Get("hNBarReg");
1016   if(hNBarReg== 0)
1017    hNBarReg   = new TH1F("hNBarReg", "NBar registered as photon",           100, 0., 5.);
1018   hNBarEM  =(TH1F*)cfile->Get("hNBarEM"); 
1019   if(hNBarEM== 0)
1020     hNBarEM   = new TH1F("hNBarEM",  "NBar registered as EM",   100, 0., 5.);
1021
1022   //primary - charged hadron (pBar excluded)
1023   hChargedReg = (TH1F*)cfile->Get("hChargedReg");
1024   if(hChargedReg== 0)
1025     hChargedReg= new TH1F("hChargedReg", "Charged hadron registered as photon",100, 0., 5.);
1026   hChargedEM  = (TH1F*)cfile->Get("hChargedEM"); 
1027   if(hChargedEM== 0)
1028     hChargedEM= new TH1F("hChargedEM","Charged registered as EM",100, 0., 5.);
1029  
1030   //primary - pBar
1031   hPbarReg = (TH1F*)cfile->Get("hPbarReg");
1032   if(hPbarReg== 0)
1033     hPbarReg= new TH1F("hPbarReg", "pBar registered as photon",100, 0., 5.);
1034   hPbarEM  = (TH1F*)cfile->Get("hPbarEM");
1035   if(hPbarEM== 0)
1036     hPbarEM= new TH1F("hPbarEM","Pbar registered as EM",100, 0., 5.);
1037   
1038
1039   //Now make some initializations
1040
1041   Int_t counter[8][5] ;      //# of registered particles 
1042   Int_t i1,i2 ;
1043   for(i1 = 0; i1<8; i1++)
1044     for(i2 = 0; i2<5; i2++)
1045       counter[i1][i2] = 0 ;
1046
1047
1048
1049   if (fRunLoader == 0x0)
1050    {
1051      AliError(Form("Error Loading session"));
1052      return;
1053    }
1054   
1055   AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(fRunLoader->GetLoader("PHOSLoader"));
1056   if ( gime == 0 ) 
1057    {
1058      AliError(Form("Could not obtain the Loader object !")); 
1059      return ;
1060    } 
1061   
1062   if (fRunLoader->TreeE() == 0x0) fRunLoader->LoadHeader();
1063   AliPHOSGeometry * phosgeom =  AliPHOSGeometry::GetInstance() ;
1064   
1065   Int_t ievent;
1066   Int_t maxevent = (Int_t)fRunLoader->TreeE()->GetEntries() ; 
1067   for ( ievent=0; ievent < maxevent ; ievent++){
1068     
1069     fRunLoader->GetEvent(ievent) ;
1070     
1071     //DP:Extract vertex position
1072     Double_t vtx[3]={0.,0.,0.} ;
1073
1074     TClonesArray * rp = gime->RecParticles() ;
1075     if(!rp) {
1076       AliError(Form("Event %d,  Can't find RecParticles", ievent)) ;
1077       return ;
1078     }
1079     TClonesArray * ts = gime->TrackSegments() ;
1080     if(!ts) {
1081       AliError(Form("Event %d,  Can't find TrackSegments", ievent)) ;
1082       return ;
1083     }
1084     TObjArray * emcrp = gime->EmcRecPoints() ;
1085     if(!emcrp){
1086       AliError(Form("Event %d,  Can't find EmcRecPoints", ievent)) ;
1087       return ;
1088     }
1089     
1090     
1091     //=========== Make spectrum of the primary photons
1092     const TParticle * primary ;
1093     Int_t iPrimary ;
1094     for( iPrimary = 0 ; iPrimary < fRunLoader->Stack()->GetNprimary() ; iPrimary++){
1095       primary = fRunLoader->Stack()->Particle(iPrimary) ;
1096       Int_t primaryType = primary->GetPdgCode() ;
1097       if( primaryType == 22 ) {
1098        //check, if photons folls onto PHOS
1099        Int_t moduleNumber ;
1100        Double_t primX, primZ ;
1101        phosgeom->ImpactOnEmc(vtx,primary->Theta(), primary->Phi(), moduleNumber, primX, primZ) ;
1102        if(moduleNumber)
1103          hPrimary->Fill(primary->Energy()) ;
1104        
1105       }
1106       
1107     }
1108     
1109     //========== Now scan over RecParticles            
1110     const AliPHOSRecParticle * recParticle ;
1111     Int_t iRecParticle ;
1112     for(iRecParticle = 0; iRecParticle < rp->GetEntriesFast(); iRecParticle++ ){
1113       recParticle = (AliPHOSRecParticle *) rp->At(iRecParticle) ;
1114       //fill histo spectrum of all RecParticles
1115       hAllRP->Fill(CorrectedEnergy(recParticle->Energy())) ;
1116       
1117       //==========find the closest primary       
1118       Int_t moduleNumberRec ;
1119       Double_t recX, recZ ;
1120       phosgeom->ImpactOnEmc(vtx,recParticle->Theta(), recParticle->Phi(), moduleNumberRec, recX, recZ) ;
1121       
1122       Double_t minDistance  = 100. ;
1123       Int_t closestPrimary = -1 ;
1124       
1125       //extract list of primaries: it is stored at EMC RecPoints
1126       Int_t emcIndex = ((AliPHOSTrackSegment *) ts->At(recParticle->GetPHOSTSIndex()))->GetEmcIndex() ;
1127       Int_t numberofprimaries ;
1128       Int_t * listofprimaries  = ((AliPHOSEmcRecPoint *) emcrp->At(emcIndex))->GetPrimaries(numberofprimaries)  ;
1129       Int_t index ;
1130       const TParticle * primary ;
1131       Double_t distance = minDistance ;
1132       Double_t dX, dZ; 
1133       Double_t dXmin = 0.; 
1134       Double_t dZmin = 0. ;
1135       for ( index = 0 ; index < numberofprimaries ; index++){
1136        primary = fRunLoader->Stack()->Particle(listofprimaries[index]) ;
1137        Int_t moduleNumber ;
1138        Double_t primX, primZ ;
1139        phosgeom->ImpactOnEmc(vtx,primary->Theta(), primary->Phi(), moduleNumber, primX, primZ) ;
1140        if(moduleNumberRec == moduleNumber) {
1141          dX = recX - primX;
1142          dZ = recZ - primZ;
1143          distance = TMath::Sqrt(dX*dX + dZ*dZ) ;
1144          if(minDistance > distance) {
1145            minDistance = distance ;
1146            dXmin = dX;
1147            dZmin = dZ;
1148            closestPrimary = listofprimaries[index] ;
1149          }
1150        }
1151       }
1152       
1153       //===========define the "type" of closest primary
1154       if(closestPrimary >=0 ){
1155        Int_t primaryCode = -1;
1156        const TParticle * primary = fRunLoader->Stack()->Particle(closestPrimary) ;
1157        Int_t primaryType = primary->GetPdgCode() ;
1158        if(primaryType == 22) // photon ?
1159          primaryCode = 0 ;
1160        else
1161          if(primaryType == 2112) // neutron
1162            primaryCode = 1 ; 
1163          else
1164            if(primaryType == -2112) // Anti neutron
1165              primaryCode = 2 ;
1166            else
1167              if(primaryType == -2122) //Anti proton
1168               primaryCode = 4 ;
1169              else {
1170               TParticle tempo(*primary) ; 
1171               if(tempo.GetPDG()->Charge())
1172                 primaryCode = 3 ;
1173              }
1174
1175        //==========Now look at the type of RecParticle
1176        Float_t energy = CorrectedEnergy(recParticle->Energy()) ;
1177        if(recParticle->GetType() == AliPHOSFastRecParticle::kNEUTRALEMFAST){
1178          hPhot->Fill(energy ) ;        
1179          switch(primaryCode){
1180          case 0:
1181            hPhotReg->Fill(energy ) ; 
1182            break ;
1183          case 1:
1184            hNReg->Fill(energy ) ; 
1185            break ;
1186          case 2:
1187            hNBarReg->Fill(energy ) ; 
1188            break ;
1189          case 3:
1190            hChargedReg->Fill(energy ) ;
1191            break ;
1192          case 4:
1193            hPbarReg->Fill(energy ) ;
1194            break ;
1195          default:
1196            break ;
1197          }
1198        }
1199        if((recParticle->GetType() == AliPHOSFastRecParticle::kNEUTRALEMFAST)||
1200           (recParticle->GetType() == AliPHOSFastRecParticle::kCHARGEDEMFAST)||
1201           (recParticle->GetType() == AliPHOSFastRecParticle::kNEUTRALEMSLOW)||
1202           (recParticle->GetType() == AliPHOSFastRecParticle::kCHARGEDEMSLOW) ){ //with EM shower
1203          hShape->Fill(energy ) ;
1204          switch(primaryCode){
1205          case 0:
1206            hPhotEM->Fill(energy ) ; 
1207            break ;
1208          case 1:
1209            hNEM->Fill(energy ) ; 
1210            break ;
1211          case 2:
1212            hNBarEM->Fill(energy ) ; 
1213            break ;
1214          case 3:
1215            hChargedEM->Fill(energy ) ; 
1216            break ;
1217          case 4:
1218            hPbarEM->Fill(energy ) ; 
1219            break ;
1220          default:
1221            break ;
1222          }
1223        }
1224        
1225        if((recParticle->GetType() == AliPHOSFastRecParticle::kNEUTRALEMFAST)||
1226           (recParticle->GetType() == AliPHOSFastRecParticle::kNEUTRALHAFAST) ||
1227           (recParticle->GetType() == AliPHOSFastRecParticle::kNEUTRALEMSLOW) ||
1228           (recParticle->GetType() == AliPHOSFastRecParticle::kNEUTRALHASLOW) ) //nuetral
1229          hVeto->Fill(energy ) ;
1230        
1231        //fill number of primaries identified as ...
1232        if(primaryCode >= 0) // Primary code defined
1233          counter[recParticle->GetType()][primaryCode]++ ; 
1234        
1235       }
1236       
1237     } // no closest primary found
1238   }     
1239   
1240   
1241   //===================  SaveHistograms
1242   cfile->cd() ;
1243   hPrimary->Write(0,kOverwrite); 
1244   hAllRP->Write(0,kOverwrite);  
1245   hPhot->Write(0,kOverwrite);  
1246   hShape->Write(0,kOverwrite); 
1247   hVeto->Write(0,kOverwrite);  
1248   hPhotReg->Write(0,kOverwrite); 
1249   hPhotEM->Write(0,kOverwrite);   
1250   hNReg ->Write(0,kOverwrite);  
1251   hNEM  ->Write(0,kOverwrite); 
1252   hNBarReg ->Write(0,kOverwrite); 
1253   hNBarEM  ->Write(0,kOverwrite); 
1254   hChargedReg ->Write(0,kOverwrite); 
1255   hChargedEM  ->Write(0,kOverwrite); 
1256   hPbarReg ->Write(0,kOverwrite); 
1257   hPbarEM  ->Write(0,kOverwrite); 
1258   
1259   cfile->Write(0,kOverwrite); 
1260   cfile->Close();
1261   delete cfile ;
1262  
1263   
1264   //print Final Table
1265   maxevent = (Int_t)gAlice->TreeE()->GetEntries() ; 
1266
1267   TString message ; 
1268   message  = "Resolutions: Analyzed %d event(s)\n" ; 
1269  
1270   message += "        Primary:    Photon  Neutron  Antineutron  Charged hadron   AntiProton\n" ; 
1271   message += "--------------------------------------------------------------------------------\n" ;
1272   message += "         kGAMMA: " ; 
1273   message += "%d %d %d %d %d\n" ; 
1274   message += "       kGAMMAHA: " ;
1275   message += "%d %d %d %d %d\n" ; 
1276   message += "     kNEUTRALEM: " ; 
1277   message += "%d %d %d %d %d\n" ; 
1278   message += "     kNEUTRALHA: " ; 
1279   message += "%d %d %d %d %d\n" ;
1280   message += "      kABSURDEM: ";
1281   message += "%d %d %d %d %d\n" ;
1282   message += "      kABSURDHA: " ;
1283   message += "%d %d %d %d %d\n" ;
1284   message += "      kELECTRON: " ;
1285   message += "%d %d %d %d %d\n" ;
1286   message += "     kCHARGEDHA: " ;  
1287   message += "%d %d %d %d %d\n" ;
1288    
1289   message += "--------------------------------------------------------------------------------" ;
1290
1291  
1292   Int_t totalInd = 0 ;
1293   for(i1 = 0; i1<8; i1++)
1294     for(i2 = 0; i2<5; i2++)
1295       totalInd+=counter[i1][i2] ;
1296   message += "Indentified particles: %d" ; 
1297   
1298  AliInfo(Form(message.Data(), maxevent, 
1299       counter[2][0], counter[2][1], counter[2][2], counter[2][3], counter[2][4], 
1300       counter[3][0], counter[3][1], counter[3][2], counter[3][3], counter[3][4], 
1301       counter[0][0], counter[0][1], counter[0][2], counter[0][3], counter[0][4], 
1302       counter[1][0], counter[1][1], counter[1][2], counter[1][3], counter[1][4], 
1303       counter[4][0], counter[4][1], counter[4][2], counter[4][3], counter[4][4], 
1304       counter[5][0], counter[5][1], counter[5][2], counter[5][3], counter[5][4], 
1305       counter[6][0], counter[6][1], counter[6][2], counter[6][3], counter[6][4], 
1306       counter[7][0], counter[7][1], counter[7][2], counter[7][3], counter[7][4], 
1307       totalInd )) ;
1308
1309 }