]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROReconstructor.cxx
NEG coating added to Be section.
[u/mrichter/AliRoot.git] / VZERO / AliVZEROReconstructor.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 ///                                                                          //
20 /// class for VZERO reconstruction                                           //
21 ///                                                                          //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include "AliRunLoader.h"
25 #include "AliRawReader.h"
26 #include "AliVZEROReconstructor.h"
27 #include "AliVZERORawStream.h"
28 #include "AliESD.h"
29
30 ClassImp(AliVZEROReconstructor)
31
32 //_____________________________________________________________________________
33 AliVZEROReconstructor:: AliVZEROReconstructor(): AliReconstructor(),
34    fESDVZERO(0x0),
35    fESD(0x0),
36    fRunLoader(0x0),
37    fCalibData(GetCalibData())
38 {
39   // Default constructor  
40   // Get calibration data
41   
42   // fCalibData = GetCalibData(); 
43 }
44
45
46 //_____________________________________________________________________________
47 AliVZEROReconstructor& AliVZEROReconstructor::operator = 
48   (const AliVZEROReconstructor& /*reconstructor*/)
49 {
50 // assignment operator
51
52   Fatal("operator =", "assignment operator not implemented");
53   return *this;
54 }
55
56 //_____________________________________________________________________________
57 AliVZEROReconstructor::~AliVZEROReconstructor()
58 {
59 // destructor
60    delete fESDVZERO; 
61    
62 }
63
64 //_____________________________________________________________________________
65 void AliVZEROReconstructor::Init(AliRunLoader* runLoader)
66 {
67 // initializer
68
69   fRunLoader = runLoader;
70   fESDVZERO  = new AliESDVZERO;
71 }
72
73 //______________________________________________________________________
74 void AliVZEROReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
75 {
76 // converts to digits
77
78   if (!digitsTree) {
79     AliError("No digits tree!");
80     return;
81   }
82
83   TClonesArray* digitsArray = new TClonesArray("AliVZEROdigit");
84   digitsTree->Branch("VZERODigit", &digitsArray);
85
86   rawReader->Reset();
87   AliVZERORawStream rawStream(rawReader);
88   if (rawStream.Next()) {
89     for(Int_t iChannel = 0; iChannel < 64; iChannel++) {
90     Int_t adc = rawStream.GetADC(iChannel);  
91     Int_t time = rawStream.GetTime(iChannel);
92     new ((*digitsArray)[digitsArray->GetEntriesFast()])
93       AliVZEROdigit(iChannel,adc,time);
94     }
95   }
96
97   digitsTree->Fill();
98 }
99
100 //______________________________________________________________________
101 void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
102                                     AliESD* esd) const
103 {
104 // fills multiplicities to the ESD
105
106   if (!digitsTree) {
107     AliError("No digits tree!");
108     return;
109   }
110
111   TClonesArray* digitsArray = NULL;
112   TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
113   digitBranch->SetAddress(&digitsArray);
114
115   Int_t   nbPMV0A = 0;
116   Int_t   nbPMV0C = 0;
117   Int_t   mTotV0A = 0;
118   Int_t   mTotV0C = 0;
119   Float_t adcV0A  = 0.0;
120   Float_t adcV0C  = 0.0;
121   Float_t multV0A[4];
122   Float_t multV0C[4];
123   Int_t   mRingV0A[4];
124   Int_t   mRingV0C[4];
125   
126   Int_t   adc[64]; 
127   Float_t mip[64];
128   for (Int_t i=0; i<64; i++){
129        adc[i] = 0;
130        mip[i] = 110.0;}
131   for (Int_t j=0; j<4; j++){
132        multV0A[j]  = 0.0;
133        multV0C[j]  = 0.0;
134        mRingV0A[j] = 0;
135        mRingV0C[j] = 0;}
136      
137   // loop over VZERO entries
138   Int_t nEntries = (Int_t)digitsTree->GetEntries();
139   for (Int_t e=0; e<nEntries; e++) {
140     digitsTree->GetEvent(e);
141
142     Int_t nDigits = digitsArray->GetEntriesFast();
143     
144     for (Int_t d=0; d<nDigits; d++) {    
145       AliVZEROdigit* digit = (AliVZEROdigit*)digitsArray->At(d);      
146       Int_t  pmNumber      = digit->PMNumber();  
147       adc[pmNumber] = digit->ADC(); 
148       // cut of ADC at MIP/2
149       if  (adc[pmNumber] > (mip[pmNumber]/2)) { 
150         if (pmNumber<=31) {
151           if (pmNumber<=7) multV0C[0]=multV0C[0]+ float(adc[pmNumber])/mip[pmNumber];
152           if (pmNumber>=8  && pmNumber<=15) multV0C[1]=multV0C[1]+ float(adc[pmNumber])/mip[pmNumber];
153           if (pmNumber>=16 && pmNumber<=23) multV0C[2]=multV0C[2]+ float(adc[pmNumber])/mip[pmNumber];
154           if (pmNumber>=24 && pmNumber<=31) multV0C[3]=multV0C[3]+ float(adc[pmNumber])/mip[pmNumber];
155           adcV0C = adcV0C + float(adc[pmNumber])/mip[pmNumber];
156           nbPMV0C++;
157         }       
158         if (pmNumber>=32 ) {
159           if (pmNumber>=32 && pmNumber<=39) multV0A[0]=multV0A[0]+ float(adc[pmNumber])/mip[pmNumber];
160           if (pmNumber>=40 && pmNumber<=47) multV0A[1]=multV0A[1]+ float(adc[pmNumber])/mip[pmNumber];
161           if (pmNumber>=48 && pmNumber<=55) multV0A[2]=multV0A[2]+ float(adc[pmNumber])/mip[pmNumber];
162           if (pmNumber>=56 && pmNumber<=63) multV0A[3]=multV0A[3]+ float(adc[pmNumber])/mip[pmNumber];
163           adcV0A = adcV0A + float(adc[pmNumber])/mip[pmNumber];
164           nbPMV0A++;
165         }
166       }
167     } // end of loop over digits
168     
169   } // end of loop over events in digits tree
170   
171   mTotV0A = int(adcV0A + 0.5);
172   mTotV0C = int(adcV0C + 0.5);
173   for (Int_t j=0; j<4; j++){       
174        mRingV0A[j] = int(multV0A[j] + 0.5);
175        mRingV0C[j] = int(multV0C[j] + 0.5);}
176      
177   AliDebug(1,Form("VZERO multiplicities : %d (V0A) %d (V0C)", mTotV0A, mTotV0C));
178   AliDebug(1,Form("Number of PMs fired  : %d (V0A) %d (V0C)", nbPMV0A, nbPMV0C));
179
180   fESDVZERO->SetNbPMV0A(nbPMV0A);
181   fESDVZERO->SetNbPMV0C(nbPMV0C);
182   fESDVZERO->SetMTotV0A(mTotV0A);
183   fESDVZERO->SetMTotV0C(mTotV0C);
184   fESDVZERO->SetMRingV0A(mRingV0A);
185   fESDVZERO->SetMRingV0C(mRingV0C);
186   
187   if (esd) { 
188     AliDebug(1, Form("Writing VZERO data to ESD tree"));
189     esd->SetVZEROData(fESDVZERO);
190   }
191 }
192
193 //_____________________________________________________________________________
194 AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri) 
195 {
196 // Sets the storage  
197
198   Bool_t deleteManager = kFALSE;
199   
200   AliCDBManager *manager = AliCDBManager::Instance();
201   AliCDBStorage *defstorage = manager->GetDefaultStorage();
202   
203   if(!defstorage || !(defstorage->Contains("VZERO"))){ 
204      AliWarning("No default storage set or default storage doesn't contain VZERO!");
205      manager->SetDefaultStorage(uri);
206      deleteManager = kTRUE;
207   }
208  
209   AliCDBStorage *storage = manager->GetDefaultStorage();
210
211   if(deleteManager){
212     AliCDBManager::Instance()->UnsetDefaultStorage();
213     defstorage = 0;   // the storage is killed by AliCDBManager::Instance()->Destroy()
214   }
215
216   return storage; 
217 }
218
219 //_____________________________________________________________________________
220 AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
221 {
222   // Gets calibration object for VZERO set
223
224   AliCDBManager *man = AliCDBManager::Instance();
225
226   AliCDBEntry *entry=0;
227
228   entry = man->Get("VZERO/Calib/Data");
229
230 //   if(!entry){
231 //     AliWarning("Load of calibration data from default storage failed!");
232 //     AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
233 //     Int_t runNumber = man->GetRun();
234 //     entry = man->GetStorage("local://$ALICE_ROOT")
235 //       ->Get("VZERO/Calib/Data",runNumber);
236 //      
237 //   }
238
239   // Retrieval of data in directory VZERO/Calib/Data:
240
241   AliVZEROCalibData *calibdata = 0;
242
243   if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
244   if (!calibdata)  AliFatal("No calibration data from calibration database !");
245
246   return calibdata;
247 }