]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROReconstructor.cxx
3a3418b81d32777fb8c087d4ee71a9c02ebc57d6
[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 "AliESDEvent.h"
29 #include "AliVZEROTriggerMask.h"
30
31 ClassImp(AliVZEROReconstructor)
32
33 //_____________________________________________________________________________
34 AliVZEROReconstructor:: AliVZEROReconstructor(): AliReconstructor(),
35    fESDVZERO(0x0),
36    fESD(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()
66 {
67 // initializer
68
69   fESDVZERO  = new AliESDVZERO;
70 }
71
72 //______________________________________________________________________
73 void AliVZEROReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
74 {
75 // converts RAW to digits
76
77   if (!digitsTree) {
78     AliError("No digits tree!");
79     return;
80   }
81
82   TClonesArray* digitsArray = new TClonesArray("AliVZEROdigit");
83   digitsTree->Branch("VZERODigit", &digitsArray);
84
85   rawReader->Reset();
86   AliVZERORawStream rawStream(rawReader);
87   if (rawStream.Next()) {  
88      Int_t ADC_max[64], adc[64], time[64];   
89      for(Int_t i=0; i<64; i++) {
90          // Search for the maximun charge in the train of 21 LHC clocks 
91          // regardless of the integrator which has been operated:
92          ADC_max[i] = 0;
93          for(Int_t iClock=0; iClock<21; iClock++){
94              if((Int_t)rawStream.GetPedestal(i,iClock) > ADC_max[i])  
95                 {ADC_max[i]=(Int_t)rawStream.GetPedestal(i,iClock);}
96          }
97          // Convert i (FEE channel numbering) to j (aliroot channel numbering)
98          Int_t j =  rawStream.GetOfflineChannel(i);
99          adc[j]  =  ADC_max[i];
100          time[j] =  rawStream.GetTime(i); 
101      }  
102      // Channels(aliroot numbering) will be ordered in the tree
103      for(Int_t iChannel = 0; iChannel < 64; iChannel++) {
104          new ((*digitsArray)[digitsArray->GetEntriesFast()])
105              AliVZEROdigit(iChannel,adc[iChannel],time[iChannel]);
106      }
107   }
108
109   digitsTree->Fill();
110 }
111
112 //______________________________________________________________________
113 void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
114                                     AliESDEvent* esd) const
115 {
116 // fills multiplicities to the ESD
117
118   if (!digitsTree) {
119     AliError("No digits tree!");
120     return;
121   }
122
123   TClonesArray* digitsArray = NULL;
124   TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
125   digitBranch->SetAddress(&digitsArray);
126
127   const Float_t mip0=110.0;
128   Short_t Multiplicity[64];
129   Float_t mult[64];  
130   Short_t   adc[64]; 
131   Short_t   time[64]; 
132   Float_t mip[64];
133   for (Int_t i=0; i<64; i++){
134        adc[i] = 0;
135        mip[i] = mip0;
136        mult[i]= 0.0;
137   }
138      
139   // loop over VZERO entries to get multiplicity
140   Int_t nEntries = (Int_t)digitsTree->GetEntries();
141   for (Int_t e=0; e<nEntries; e++) {
142     digitsTree->GetEvent(e);
143
144     Int_t nDigits = digitsArray->GetEntriesFast();
145     
146     for (Int_t d=0; d<nDigits; d++) {    
147       AliVZEROdigit* digit = (AliVZEROdigit*)digitsArray->At(d);      
148       Int_t  pmNumber      = digit->PMNumber();  
149       adc[pmNumber] = (Short_t) digit->ADC(); 
150       time[pmNumber] = (Short_t) digit->Time();
151       // cut of ADC at MIP/2
152       if  (adc[pmNumber] > (mip[pmNumber]/2)) 
153         mult[pmNumber] += float(adc[pmNumber])/mip[pmNumber];
154     } // end of loop over digits
155   } // end of loop over events in digits tree
156   
157   for (Int_t j=0; j<64; j++) Multiplicity[j] = short(mult[j]+0.5);       
158   fESDVZERO->SetMultiplicity(Multiplicity);
159   fESDVZERO->SetADC(adc);
160   fESDVZERO->SetTime(time);
161
162   // now get the trigger mask
163
164   AliVZEROTriggerMask *TriggerMask = new AliVZEROTriggerMask();
165   TriggerMask->SetAdcThreshold(mip0/2.0);
166   TriggerMask->SetTimeWindowWidthBBA(50);
167   TriggerMask->SetTimeWindowWidthBGA(20);
168   TriggerMask->SetTimeWindowWidthBBC(50);
169   TriggerMask->SetTimeWindowWidthBGC(20);
170   TriggerMask->FillMasks(digitsTree,digitsArray);
171
172   fESDVZERO->SetBBtriggerV0A(TriggerMask->GetBBtriggerV0A());
173   fESDVZERO->SetBGtriggerV0A(TriggerMask->GetBGtriggerV0A());
174   fESDVZERO->SetBBtriggerV0C(TriggerMask->GetBBtriggerV0C());
175   fESDVZERO->SetBGtriggerV0C(TriggerMask->GetBGtriggerV0C());
176   
177   if (esd) { 
178     AliDebug(1, Form("Writing VZERO data to ESD tree"));
179     esd->SetVZEROData(fESDVZERO);
180   }
181 }
182
183 //_____________________________________________________________________________
184 AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri) 
185 {
186 // Sets the storage  
187
188   Bool_t deleteManager = kFALSE;
189   
190   AliCDBManager *manager = AliCDBManager::Instance();
191   AliCDBStorage *defstorage = manager->GetDefaultStorage();
192   
193   if(!defstorage || !(defstorage->Contains("VZERO"))){ 
194      AliWarning("No default storage set or default storage doesn't contain VZERO!");
195      manager->SetDefaultStorage(uri);
196      deleteManager = kTRUE;
197   }
198  
199   AliCDBStorage *storage = manager->GetDefaultStorage();
200
201   if(deleteManager){
202     AliCDBManager::Instance()->UnsetDefaultStorage();
203     defstorage = 0;   // the storage is killed by AliCDBManager::Instance()->Destroy()
204   }
205
206   return storage; 
207 }
208
209 //_____________________________________________________________________________
210 AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
211 {
212   // Gets calibration object for VZERO set
213
214   AliCDBManager *man = AliCDBManager::Instance();
215
216   AliCDBEntry *entry=0;
217
218   entry = man->Get("VZERO/Calib/Data");
219
220 //   if(!entry){
221 //     AliWarning("Load of calibration data from default storage failed!");
222 //     AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
223 //     Int_t runNumber = man->GetRun();
224 //     entry = man->GetStorage("local://$ALICE_ROOT")
225 //       ->Get("VZERO/Calib/Data",runNumber);
226 //      
227 //   }
228
229   // Retrieval of data in directory VZERO/Calib/Data:
230
231   AliVZEROCalibData *calibdata = 0;
232
233   if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
234   if (!calibdata)  AliFatal("No calibration data from calibration database !");
235
236   return calibdata;
237 }