]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROReconstructor.cxx
Get in sync with the base class
[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, GetMIP(pmNumber));
206         // cut of ADC at 1MIP/2 
207         if (adc[pmNumber] > (int(1.0/GetMIP(pmNumber)) /2) ) 
208             mult[pmNumber] += float(adc[pmNumber])*GetMIP(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
306 //_____________________________________________________________________________
307 Float_t AliVZEROReconstructor::GetMIP(Int_t channel) const {
308
309 // Computes the MIP conversion factor - MIP per ADC channel - 
310 // Argument passed is the PM number (aliroot numbering)
311
312   Float_t P0[64] = {
313   7.094891, 7.124938, 7.089708, 7.098169, 7.094482, 7.147250, 7.170978, 7.183392, 
314   7.145760, 7.148096, 7.153840, 7.143544, 7.186069, 7.194580, 7.203516, 7.195176, 
315   7.188333, 7.198607, 7.209412, 7.226565, 7.221695, 7.205132, 7.191238, 7.227724, 
316   7.232810, 7.252655, 7.230309, 7.273518, 7.273518, 7.242969, 7.252859, 7.252655, 
317   7.026802, 7.079913, 7.134147, 7.092387, 7.079561, 7.072848, 7.123192, 7.003141, 
318   7.024667, 7.124784, 7.123442, 7.129744, 7.110671, 7.143031, 7.139439, 7.178109, 
319   7.247803, 7.139396, 7.293809, 7.094454, 6.992198, 7.206448, 7.244765, 7.056197, 
320   7.263595, 7.138569, 7.089582, 7.215683, 7.266183, 7.165123, 7.243276, 7.235135 };
321   Float_t P1[64] = {
322   0.135569, 0.146405, 0.142425, 0.144278, 0.142307, 0.141648, 0.128477, 0.138239, 
323   0.144173, 0.143419, 0.143572, 0.144482, 0.138024, 0.136542, 0.135955, 0.138537, 
324   0.148521, 0.141999, 0.139627, 0.130014, 0.134970, 0.135635, 0.139094, 0.140634, 
325   0.137971, 0.142080, 0.142793, 0.142778, 0.142778, 0.146045, 0.139133, 0.142080, 
326   0.144121, 0.142311, 0.136564, 0.142686, 0.138792, 0.166285, 0.136387, 0.155391, 
327   0.176082, 0.140408, 0.164738, 0.144270, 0.142766, 0.147486, 0.141951, 0.138012, 
328   0.132394, 0.142849, 0.140477, 0.144592, 0.141558, 0.157646, 0.143758, 0.173385, 
329   0.146489, 0.143279, 0.145230, 0.147203, 0.147333, 0.144979, 0.148597, 0.138985 };
330
331 // High Voltage retrieval from Calibration Data Base:  
332   Float_t  HV = fCalibData->GetMeanHV(channel);  
333   Float_t MIP = 0.5/TMath::Exp((TMath::Log(HV) - P0[channel] )/P1[channel]);
334   return MIP; 
335
336 }