]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROReconstructor.cxx
Correcting a long standing bug in the mapping of short slats
[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 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     for(Int_t iChannel = 0; iChannel < 64; iChannel++) {
89     Int_t adc = rawStream.GetADC(iChannel);  
90     Int_t time = rawStream.GetTime(iChannel);
91     new ((*digitsArray)[digitsArray->GetEntriesFast()])
92       AliVZEROdigit(iChannel,adc,time);
93     }
94   }
95
96   digitsTree->Fill();
97 }
98
99 //______________________________________________________________________
100 void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
101                                     AliESDEvent* esd) const
102 {
103 // fills multiplicities to the ESD
104
105   if (!digitsTree) {
106     AliError("No digits tree!");
107     return;
108   }
109
110   TClonesArray* digitsArray = NULL;
111   TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
112   digitBranch->SetAddress(&digitsArray);
113
114   const Float_t mip0=110.0;
115   Short_t Multiplicity[64];
116   Float_t mult[64];  
117   Short_t   adc[64]; 
118   Short_t   time[64]; 
119   Float_t mip[64];
120   for (Int_t i=0; i<64; i++){
121        adc[i] = 0;
122        mip[i] = mip0;
123        mult[i]= 0.0;
124   }
125      
126   // loop over VZERO entries to get multiplicity
127   Int_t nEntries = (Int_t)digitsTree->GetEntries();
128   for (Int_t e=0; e<nEntries; e++) {
129     digitsTree->GetEvent(e);
130
131     Int_t nDigits = digitsArray->GetEntriesFast();
132     
133     for (Int_t d=0; d<nDigits; d++) {    
134       AliVZEROdigit* digit = (AliVZEROdigit*)digitsArray->At(d);      
135       Int_t  pmNumber      = digit->PMNumber();  
136       adc[pmNumber] = (Short_t) digit->ADC(); 
137       time[pmNumber] = (Short_t) digit->Time();
138       // cut of ADC at MIP/2
139       if  (adc[pmNumber] > (mip[pmNumber]/2)) 
140         mult[pmNumber] += float(adc[pmNumber])/mip[pmNumber];
141     } // end of loop over digits
142   } // end of loop over events in digits tree
143   
144   for (Int_t j=0; j<64; j++) Multiplicity[j] = short(mult[j]+0.5);       
145   fESDVZERO->SetMultiplicity(Multiplicity);
146   fESDVZERO->SetADC(adc);
147   fESDVZERO->SetTime(time);
148
149   // now get the trigger mask
150
151   AliVZEROTriggerMask *TriggerMask = new AliVZEROTriggerMask();
152   TriggerMask->SetAdcThreshold(mip0/2.0);
153   TriggerMask->SetTimeWindowWidthBBA(50);
154   TriggerMask->SetTimeWindowWidthBGA(20);
155   TriggerMask->SetTimeWindowWidthBBC(50);
156   TriggerMask->SetTimeWindowWidthBGC(20);
157   TriggerMask->FillMasks(digitsTree,digitsArray);
158
159   fESDVZERO->SetBBtriggerV0A(TriggerMask->GetBBtriggerV0A());
160   fESDVZERO->SetBGtriggerV0A(TriggerMask->GetBGtriggerV0A());
161   fESDVZERO->SetBBtriggerV0C(TriggerMask->GetBBtriggerV0C());
162   fESDVZERO->SetBGtriggerV0C(TriggerMask->GetBGtriggerV0C());
163   
164   if (esd) { 
165     AliDebug(1, Form("Writing VZERO data to ESD tree"));
166     esd->SetVZEROData(fESDVZERO);
167   }
168 }
169
170 //_____________________________________________________________________________
171 AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri) 
172 {
173 // Sets the storage  
174
175   Bool_t deleteManager = kFALSE;
176   
177   AliCDBManager *manager = AliCDBManager::Instance();
178   AliCDBStorage *defstorage = manager->GetDefaultStorage();
179   
180   if(!defstorage || !(defstorage->Contains("VZERO"))){ 
181      AliWarning("No default storage set or default storage doesn't contain VZERO!");
182      manager->SetDefaultStorage(uri);
183      deleteManager = kTRUE;
184   }
185  
186   AliCDBStorage *storage = manager->GetDefaultStorage();
187
188   if(deleteManager){
189     AliCDBManager::Instance()->UnsetDefaultStorage();
190     defstorage = 0;   // the storage is killed by AliCDBManager::Instance()->Destroy()
191   }
192
193   return storage; 
194 }
195
196 //_____________________________________________________________________________
197 AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
198 {
199   // Gets calibration object for VZERO set
200
201   AliCDBManager *man = AliCDBManager::Instance();
202
203   AliCDBEntry *entry=0;
204
205   entry = man->Get("VZERO/Calib/Data");
206
207 //   if(!entry){
208 //     AliWarning("Load of calibration data from default storage failed!");
209 //     AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
210 //     Int_t runNumber = man->GetRun();
211 //     entry = man->GetStorage("local://$ALICE_ROOT")
212 //       ->Get("VZERO/Calib/Data",runNumber);
213 //      
214 //   }
215
216   // Retrieval of data in directory VZERO/Calib/Data:
217
218   AliVZEROCalibData *calibdata = 0;
219
220   if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
221   if (!calibdata)  AliFatal("No calibration data from calibration database !");
222
223   return calibdata;
224 }