]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSv0hits.cxx
b290081326a4be66c92436e3b7aa29db02f69167
[u/mrichter/AliRoot.git] / PHOS / AliPHOSv0hits.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 // Version of AliPHOSv0 which allows for keeping all hits in TreeH
19 //                  
20 //*-- Author: Gines MARTINEZ (SUBATECH)
21
22
23 // --- ROOT system ---
24
25 #include "TBRIK.h"
26 #include "TNode.h"
27 #include "TRandom.h"
28
29 // --- Standard library ---
30
31 #include <stdio.h>
32 #include <string.h>
33 #include <stdlib.h>
34 #include <strstream.h>
35
36 // --- AliRoot header files ---
37
38 #include "AliPHOSv0_hits.h"
39 #include "AliPHOSHit.h"
40 #include "AliPHOSDigit.h"
41 #include "AliPHOSReconstructioner.h"
42 #include "AliRun.h"
43 #include "AliConst.h"
44
45 ClassImp(AliPHOSv0hits)
46
47 //____________________________________________________________________________
48 AliPHOSv0hits::AliPHOSv0hits()
49 {
50   // ctor
51   fNTmpHits = 0 ; 
52   fTmpHits  = 0 ; 
53 }
54
55 //____________________________________________________________________________
56 AliPHOSv0hits::AliPHOSv0hits(const char *name, const char *title):
57   AliPHOSv0(name,title)
58 {
59    fHits= new TClonesArray("AliPHOSHit",1000) ;
60 }
61
62 //____________________________________________________________________________
63 AliPHOSv0hits::~AliPHOSv0hits()
64 {
65   // dtor
66   fTmpHits->Delete() ; 
67   delete fTmpHits ;
68   fTmpHits = 0 ; 
69
70   fEmcClusters->Delete() ; 
71   delete fEmcClusters ; 
72   fEmcClusters = 0 ; 
73
74   fPpsdClusters->Delete() ;
75   delete fPpsdClusters ;
76   fPpsdClusters = 0 ; 
77
78   fTrackSegments->Delete() ; 
79   delete fTrackSegments ;
80   fTrackSegments = 0 ; 
81 }
82
83 //____________________________________________________________________________
84 void AliPHOSv0hits::AddHit(Int_t primary, Int_t Id, Float_t * hits)
85 {
86   // Add a hit to the hit list.
87   // In this version of AliPHOSv0, a PHOS hit is real geant 
88   // hits in a single crystal or in a single PPSD gas cell
89
90   //  cout << "Primary particle is " << primary << endl;
91   //cout << "Vol Id is " << Id << endl;
92   //cout << "hits is " << hits[0] << "  " << hits[1] << "  " << hits[2] << "   " << hits[3] <<endl;
93
94   cout << " Adding a hit number " << fNhits << endl ;
95
96   TClonesArray &ltmphits = *fHits ;
97   AliPHOSHit *newHit ;
98
99   //  fHits->Print("");
100
101   newHit = new AliPHOSHit(primary, Id, hits) ;
102
103   // We DO want to save in TreeH the raw hits 
104   //  TClonesArray &lhits = *fHits;
105   cout << " Adding a hit to fHits TCloneArray number " << fNhits << endl ;     
106   new(ltmphits[fNhits]) AliPHOSHit(*newHit) ;
107   fNhits++ ;
108
109   cout << " Added a hit to fHits TCloneArray number " << fNhits << endl ; 
110   // We do not want to save in TreeH the raw hits 
111   //   new(lhits[fNhits]) AliPHOSHit(*newHit) ;    
112   //   fNhits++ ;
113
114   // Please note that the fTmpHits array must survive up to the
115   // end of the events, so it does not appear e.g. in ResetHits() (
116   // which is called at the end of each primary).  
117
118   delete newHit;
119
120 }
121
122
123
124
125 //___________________________________________________________________________
126 void AliPHOSv0hits::FinishEvent()
127 {
128   // Makes the digits from the sum of summed hit in a single crystal or PPSD gas cell
129   // Adds to the energy the electronic noise
130   // Keeps digits with energy above fDigitThreshold
131
132   // Save the cumulated hits instead of raw hits (need to create the branch myself)
133   // It is put in the Digit Tree because the TreeH is filled after each primary
134   // and the TreeD at the end of the event.
135   
136   Int_t i ;
137   Int_t relid[4];
138   Int_t j ; 
139   TClonesArray &lDigits = *fDigits ;
140   AliPHOSHit  * hit ;
141   AliPHOSDigit * newdigit ;
142   AliPHOSDigit * curdigit ;
143   Bool_t deja = kFALSE ; 
144   
145   for ( i = 0 ; i < fNhits ; i++ ) {
146     hit = (AliPHOSHit*)fHits->At(i) ;
147     newdigit = new AliPHOSDigit( hit->GetPrimary(), hit->GetId(), Digitize( hit->GetEnergy() ) ) ;
148     deja =kFALSE ;
149     for ( j = 0 ; j < fNdigits ;  j++) { 
150       curdigit = (AliPHOSDigit*) lDigits[j] ;
151       if ( *curdigit == *newdigit) {
152         *curdigit = *curdigit + *newdigit ; 
153         deja = kTRUE ; 
154       }
155     }
156     if ( !deja ) {
157       new(lDigits[fNdigits]) AliPHOSDigit(* newdigit) ;
158       fNdigits++ ;  
159     }
160  
161     delete newdigit ;    
162   } 
163   
164   // Noise induced by the PIN diode of the PbWO crystals
165
166   Float_t energyandnoise ;
167   for ( i = 0 ; i < fNdigits ; i++ ) {
168     newdigit =  (AliPHOSDigit * ) fDigits->At(i) ;
169     fGeom->AbsToRelNumbering(newdigit->GetId(), relid) ;
170
171     if (relid[1]==0){   // Digits belong to EMC (PbW0_4 crystals)
172       energyandnoise = newdigit->GetAmp() + Digitize(gRandom->Gaus(0., fPinElectronicNoise)) ;
173
174       if (energyandnoise < 0 ) 
175         energyandnoise = 0 ;
176
177       if ( newdigit->GetAmp() < fDigitThreshold ) // if threshold not surpassed, remove digit from list
178         fDigits->RemoveAt(i) ; 
179     }
180   }
181   
182   fDigits->Compress() ;  
183
184   fNdigits =  fDigits->GetEntries() ; 
185   for (i = 0 ; i < fNdigits ; i++) { 
186     newdigit = (AliPHOSDigit *) fDigits->At(i) ; 
187     newdigit->SetIndexInList(i) ; 
188   }
189
190 }
191