]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROReconstructor.cxx
Obsolete.
[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 #include "AliESDfriend.h"
31 #include "AliESDVZEROfriend.h"
32
33 ClassImp(AliVZEROReconstructor)
34
35 //_____________________________________________________________________________
36 AliVZEROReconstructor:: AliVZEROReconstructor(): AliReconstructor(),
37    fESDVZERO(0x0),
38    fESD(0x0),
39    fESDVZEROfriend(0x0),
40    fCalibData(GetCalibData())
41 {
42   // Default constructor  
43   // Get calibration data
44   
45   // fCalibData = GetCalibData(); 
46
47 }
48
49
50 //_____________________________________________________________________________
51 AliVZEROReconstructor& AliVZEROReconstructor::operator = 
52   (const AliVZEROReconstructor& /*reconstructor*/)
53 {
54 // assignment operator
55
56   Fatal("operator =", "assignment operator not implemented");
57   return *this;
58 }
59
60 //_____________________________________________________________________________
61 AliVZEROReconstructor::~AliVZEROReconstructor()
62 {
63 // destructor
64
65    delete fESDVZERO;
66    delete fESDVZEROfriend;
67 }
68
69 //_____________________________________________________________________________
70 void AliVZEROReconstructor::Init()
71 {
72 // initializer
73
74   fESDVZERO  = new AliESDVZERO;
75   fESDVZEROfriend = new AliESDVZEROfriend;
76 }
77
78 //______________________________________________________________________
79 void AliVZEROReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
80 {
81 // converts RAW to digits - pedestal is subtracted 
82
83   if (!digitsTree) {
84     AliError("No digits tree!");
85     return;
86   }
87
88   TClonesArray* digitsArray = new TClonesArray("AliVZEROdigit");
89   digitsTree->Branch("VZERODigit", &digitsArray);
90
91   fESDVZEROfriend->Reset();
92
93   rawReader->Reset();
94   AliVZERORawStream rawStream(rawReader);
95   if (rawStream.Next()) {  
96      Int_t ADC_max[64], adc[64], time[64], width[64], BBFlag[64], BGFlag[64];   
97      for(Int_t i=0; i<64; i++) {
98          // Search for the maximum charge in the train of 21 LHC clocks 
99          // regardless of the integrator which has been operated:
100          ADC_max[i] = 0;
101          Int_t imax = 0;
102          for(Int_t iClock=0; iClock<21; iClock++){
103              if((Int_t)rawStream.GetPedestal(i,iClock) > ADC_max[i])  
104                 {ADC_max[i]=(Int_t)rawStream.GetPedestal(i,iClock);
105                  imax      = iClock;}
106          }
107          // Convert i (FEE channel numbering) to j (aliroot channel numbering)
108          Int_t j   =  rawStream.GetOfflineChannel(i);
109          adc[j]    =  ADC_max[i];
110          time[j]   =  rawStream.GetTime(i);
111          width[j]  =  rawStream.GetWidth(i);
112          BBFlag[j] =  rawStream.GetBBFlag(i,imax);
113          BGFlag[j] =  rawStream.GetBGFlag(i,imax); 
114
115          // Filling the esd friend object
116          fESDVZEROfriend->SetBBScalers(j,rawStream.GetBBScalers(i));
117          fESDVZEROfriend->SetBGScalers(j,rawStream.GetBGScalers(i));
118          for (Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++) {
119            fESDVZEROfriend->SetChargeMB(j,iBunch,rawStream.GetChargeMB(i,iBunch));
120            fESDVZEROfriend->SetIntMBFlag(j,iBunch,rawStream.GetIntMBFlag(i,iBunch));
121            fESDVZEROfriend->SetBBMBFlag(j,iBunch,rawStream.GetBBMBFlag(i,iBunch));
122            fESDVZEROfriend->SetBGMBFlag(j,iBunch,rawStream.GetBGMBFlag(i,iBunch));
123          }
124          for (Int_t iEv = 0; iEv < AliESDVZEROfriend::kNEvOfInt; iEv++) {
125            fESDVZEROfriend->SetPedestal(j,iEv,rawStream.GetPedestal(i,iEv));
126            fESDVZEROfriend->SetIntegratorFlag(j,iEv,rawStream.GetIntegratorFlag(i,iEv));
127            fESDVZEROfriend->SetBBFlag(j,iEv,rawStream.GetBBFlag(i,iEv));
128            fESDVZEROfriend->SetBGFlag(j,iEv,rawStream.GetBGFlag(i,iEv));
129          }
130          fESDVZEROfriend->SetTime(j,rawStream.GetTime(i));
131          fESDVZEROfriend->SetWidth(j,rawStream.GetWidth(i));
132      }  
133
134      // Filling the esd friend object
135      fESDVZEROfriend->SetTriggerInputs(rawStream.GetTriggerInputs());
136      fESDVZEROfriend->SetTriggerInputsMask(rawStream.GetTriggerInputsMask());
137
138      for(Int_t iScaler = 0; iScaler < AliESDVZEROfriend::kNScalers; iScaler++)
139        fESDVZEROfriend->SetTriggerScalers(iScaler,rawStream.GetTriggerScalers(iScaler));
140
141      for (Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++)
142        fESDVZEROfriend->SetBunchNumbersMB(iBunch,rawStream.GetBunchNumbersMB(iBunch));
143      
144
145      // Channels(aliroot numbering) will be ordered in the tree
146      for(Int_t iChannel = 0; iChannel < 64; iChannel++) {
147          new ((*digitsArray)[digitsArray->GetEntriesFast()])
148              AliVZEROdigit(iChannel, adc[iChannel], time[iChannel],
149                            width[iChannel], BBFlag[iChannel], BGFlag[iChannel]);
150      }
151   }
152
153   digitsTree->Fill();
154 }
155
156 //______________________________________________________________________
157 void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
158                                     AliESDEvent* esd) const
159 {
160 // fills multiplicities to the ESD
161
162   if (!digitsTree) {
163     AliError("No digits tree!");
164     return;
165   }
166
167   TClonesArray* digitsArray = NULL;
168   TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
169   digitBranch->SetAddress(&digitsArray);
170
171   Short_t Multiplicity[64];
172   Float_t   mult[64];  
173   Short_t    adc[64]; 
174   Short_t   time[64]; 
175   Short_t  width[64];
176   Bool_t  BBFlag[64];
177   Bool_t  BGFlag[64];
178    
179   for (Int_t i=0; i<64; i++){
180        adc[i]    = 0;
181        mult[i]   = 0.0;
182        time[i]   = 0;
183        width[i]  = 0;
184        BBFlag[i] = kFALSE;
185        BGFlag[i] = kFALSE;
186   }
187      
188   // loop over VZERO entries to get multiplicity
189   Int_t nEntries = (Int_t)digitsTree->GetEntries();
190   for (Int_t e=0; e<nEntries; e++) {
191     digitsTree->GetEvent(e);
192
193     Int_t nDigits = digitsArray->GetEntriesFast();
194     
195     for (Int_t d=0; d<nDigits; d++) {    
196         AliVZEROdigit* digit = (AliVZEROdigit*)digitsArray->At(d);      
197         Int_t  pmNumber      = digit->PMNumber(); 
198         // Pedestal retrieval and suppression: 
199         Int_t  pedestal      = int(fCalibData->GetPedestal(d));
200         adc[pmNumber]   = (Short_t) digit->ADC() - pedestal; 
201         time[pmNumber]  = (Short_t) digit->Time();
202                 width[pmNumber] = (Short_t) digit->Width();
203                 BBFlag[pmNumber]= digit->BBFlag();
204                 BGFlag[pmNumber]= digit->BGFlag();
205         // printf("PM = %d,  MIP per ADC channel = %f \n",pmNumber, fCalibData->GetMIPperADC(pmNumber));
206         // cut of ADC at 1MIP/2 
207         if (adc[pmNumber] > (int(1.0/fCalibData->GetMIPperADC(pmNumber)) /2) ) 
208             mult[pmNumber] += float(adc[pmNumber])*fCalibData->GetMIPperADC(pmNumber);
209     } // end of loop over digits
210   } // end of loop over events in digits tree
211   
212   for (Int_t j=0; j<64; j++) Multiplicity[j] = short(mult[j]+0.5); 
213         
214   fESDVZERO->SetMultiplicity(Multiplicity);
215   fESDVZERO->SetADC(adc);
216   fESDVZERO->SetTime(time);
217   fESDVZERO->SetWidth(width);
218   fESDVZERO->SetBBFlag(BBFlag);
219   fESDVZERO->SetBGFlag(BGFlag);
220
221   // now get the trigger mask
222
223   AliVZEROTriggerMask *TriggerMask = new AliVZEROTriggerMask();
224   TriggerMask->SetAdcThreshold(20.0/2.0);
225   TriggerMask->SetTimeWindowWidthBBA(50);
226   TriggerMask->SetTimeWindowWidthBGA(20);
227   TriggerMask->SetTimeWindowWidthBBC(50);
228   TriggerMask->SetTimeWindowWidthBGC(20);
229   TriggerMask->FillMasks(digitsTree,digitsArray);
230
231   fESDVZERO->SetBBtriggerV0A(TriggerMask->GetBBtriggerV0A());
232   fESDVZERO->SetBGtriggerV0A(TriggerMask->GetBGtriggerV0A());
233   fESDVZERO->SetBBtriggerV0C(TriggerMask->GetBBtriggerV0C());
234   fESDVZERO->SetBGtriggerV0C(TriggerMask->GetBGtriggerV0C());
235   
236   if (esd) { 
237      AliDebug(1, Form("Writing VZERO data to ESD tree"));
238      esd->SetVZEROData(fESDVZERO);
239   }
240
241   if (esd) {
242     AliESDfriend *fr = (AliESDfriend*)esd->FindListObject("AliESDfriend");
243     if (fr) {
244       AliDebug(1, Form("Writing VZERO friend data to ESD tree"));
245       fr->SetVZEROfriend(fESDVZEROfriend);
246     }
247   }
248 }
249
250 //_____________________________________________________________________________
251 AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri) 
252 {
253 // Sets the storage  
254
255   Bool_t deleteManager = kFALSE;
256   
257   AliCDBManager *manager = AliCDBManager::Instance();
258   AliCDBStorage *defstorage = manager->GetDefaultStorage();
259   
260   if(!defstorage || !(defstorage->Contains("VZERO"))){ 
261      AliWarning("No default storage set or default storage doesn't contain VZERO!");
262      manager->SetDefaultStorage(uri);
263      deleteManager = kTRUE;
264   }
265  
266   AliCDBStorage *storage = manager->GetDefaultStorage();
267
268   if(deleteManager){
269      AliCDBManager::Instance()->UnsetDefaultStorage();
270      defstorage = 0;   // the storage is killed by AliCDBManager::Instance()->Destroy()
271   }
272
273   return storage; 
274 }
275
276 //_____________________________________________________________________________
277 AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
278 {
279   // Gets calibration object for VZERO set
280
281   AliCDBManager *man = AliCDBManager::Instance();
282
283   AliCDBEntry *entry=0;
284
285   entry = man->Get("VZERO/Calib/Data");
286
287 //   if(!entry){
288 //     AliWarning("Load of calibration data from default storage failed!");
289 //     AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
290 //     Int_t runNumber = man->GetRun();
291 //     entry = man->GetStorage("local://$ALICE_ROOT")
292 //       ->Get("VZERO/Calib/Data",runNumber);
293 //      
294 //   }
295
296   // Retrieval of data in directory VZERO/Calib/Data:
297
298   AliVZEROCalibData *calibdata = 0;
299
300   if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
301   if (!calibdata)  AliFatal("No calibration data from calibration database !");
302
303   return calibdata;
304 }
305