]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROReconstructor.cxx
1. Leading time was not decoded properly (there are coarse and fine gains in the...
[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 "AliGRPObject.h"
27 #include "AliCDBManager.h"
28 #include "AliCDBStorage.h"
29 #include "AliCDBEntry.h"
30 #include "AliVZEROReconstructor.h"
31 #include "AliVZERORawStream.h"
32 #include "AliESDEvent.h"
33 #include "AliVZEROTriggerMask.h"
34 #include "AliESDfriend.h"
35 #include "AliESDVZEROfriend.h"
36 #include "AliVZEROdigit.h"
37
38 ClassImp(AliVZEROReconstructor)
39
40 //_____________________________________________________________________________
41 AliVZEROReconstructor:: AliVZEROReconstructor(): AliReconstructor(),
42                         fESDVZERO(0x0),
43                         fESD(0x0),
44                         fESDVZEROfriend(0x0),
45                         fCalibData(GetCalibData()),
46                         fCollisionMode(0),
47                         fBeamEnergy(0.)
48 {
49   // Default constructor  
50   // Get calibration data
51   
52   // fCalibData = GetCalibData(); 
53
54 }
55
56
57 //_____________________________________________________________________________
58 AliVZEROReconstructor& AliVZEROReconstructor::operator = 
59   (const AliVZEROReconstructor& /*reconstructor*/)
60 {
61 // assignment operator
62
63   Fatal("operator =", "assignment operator not implemented");
64   return *this;
65 }
66
67 //_____________________________________________________________________________
68 AliVZEROReconstructor::~AliVZEROReconstructor()
69 {
70 // destructor
71
72    delete fESDVZERO;
73    delete fESDVZEROfriend;
74 }
75
76 //_____________________________________________________________________________
77 void AliVZEROReconstructor::Init()
78 {
79 // initializer
80
81   fESDVZERO  = new AliESDVZERO;
82   fESDVZEROfriend = new AliESDVZEROfriend;
83   
84   GetCollisionMode();  // fCollisionMode =1 for Pb-Pb simulated data
85 }
86
87 //______________________________________________________________________
88 void AliVZEROReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
89 {
90 // converts RAW to digits - pedestal is subtracted 
91
92   if (!digitsTree) {
93     AliError("No digits tree!");
94     return;
95   }
96
97   TClonesArray* digitsArray = new TClonesArray("AliVZEROdigit");
98   digitsTree->Branch("VZERODigit", &digitsArray);
99
100   fESDVZEROfriend->Reset();
101
102   rawReader->Reset();
103   AliVZERORawStream rawStream(rawReader);
104   if (rawStream.Next()) {  
105      Float_t ADC_max[64], adc[64]; 
106      Bool_t BBFlag[64], BGFlag[64], integrator[64]; 
107      Float_t time[64], width[64],;  
108      for(Int_t i=0; i<64; i++) {
109          // Search for the maximum charge in the train of 21 LHC clocks 
110          // regardless of the integrator which has been operated:
111          ADC_max[i] = 0.0;
112          Int_t imax = 0;
113          for(Int_t iClock=0; iClock<21; iClock++){
114              if(rawStream.GetPedestal(i,iClock) > ADC_max[i])  
115                 {ADC_max[i]= rawStream.GetPedestal(i,iClock);
116                  imax      = iClock;}
117          }
118          // Convert i (FEE channel numbering) to j (aliroot channel numbering)
119          Int_t j       =  rawStream.GetOfflineChannel(i);
120          adc[j]        =  ADC_max[i];
121          time[j]       =  rawStream.GetTime(i);
122          width[j]      =  rawStream.GetWidth(i);
123          BBFlag[j]     =  rawStream.GetBBFlag(i,imax);
124          BGFlag[j]     =  rawStream.GetBGFlag(i,imax); 
125          integrator[j] =  rawStream.GetIntegratorFlag(i,imax); 
126
127          // Filling the esd friend object
128          fESDVZEROfriend->SetBBScalers(j,rawStream.GetBBScalers(i));
129          fESDVZEROfriend->SetBGScalers(j,rawStream.GetBGScalers(i));
130          for (Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++) {
131              fESDVZEROfriend->SetChargeMB(j,iBunch,rawStream.GetChargeMB(i,iBunch));
132              fESDVZEROfriend->SetIntMBFlag(j,iBunch,rawStream.GetIntMBFlag(i,iBunch));
133              fESDVZEROfriend->SetBBMBFlag(j,iBunch,rawStream.GetBBMBFlag(i,iBunch));
134              fESDVZEROfriend->SetBGMBFlag(j,iBunch,rawStream.GetBGMBFlag(i,iBunch));
135          }
136          for (Int_t iEv = 0; iEv < AliESDVZEROfriend::kNEvOfInt; iEv++) {
137              fESDVZEROfriend->SetPedestal(j,iEv,rawStream.GetPedestal(i,iEv));
138              fESDVZEROfriend->SetIntegratorFlag(j,iEv,rawStream.GetIntegratorFlag(i,iEv));
139              fESDVZEROfriend->SetBBFlag(j,iEv,rawStream.GetBBFlag(i,iEv));
140              fESDVZEROfriend->SetBGFlag(j,iEv,rawStream.GetBGFlag(i,iEv));
141          }
142          fESDVZEROfriend->SetTime(j,rawStream.GetTime(i));
143          fESDVZEROfriend->SetWidth(j,rawStream.GetWidth(i));
144      }  
145
146      // Filling the esd friend object
147      fESDVZEROfriend->SetTriggerInputs(rawStream.GetTriggerInputs());
148      fESDVZEROfriend->SetTriggerInputsMask(rawStream.GetTriggerInputsMask());
149
150      for(Int_t iScaler = 0; iScaler < AliESDVZEROfriend::kNScalers; iScaler++)
151          fESDVZEROfriend->SetTriggerScalers(iScaler,rawStream.GetTriggerScalers(iScaler));
152
153      for(Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++)
154          fESDVZEROfriend->SetBunchNumbersMB(iBunch,rawStream.GetBunchNumbersMB(iBunch));
155      
156
157      // Channels(aliroot numbering) will be ordered in the tree
158      for(Int_t iChannel = 0; iChannel < 64; iChannel++) {
159          new ((*digitsArray)[digitsArray->GetEntriesFast()])
160              AliVZEROdigit(iChannel, adc[iChannel], time[iChannel],
161                            width[iChannel], BBFlag[iChannel], BGFlag[iChannel],integrator[iChannel]);
162      }
163   }
164
165   digitsTree->Fill();
166 }
167
168 //______________________________________________________________________
169 void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
170                                     AliESDEvent* esd) const
171 {
172 // fills multiplicities to the ESD
173     
174   if (!digitsTree) {
175       AliError("No digits tree!");
176       return;
177   }
178
179   TClonesArray* digitsArray = NULL;
180   TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
181   digitBranch->SetAddress(&digitsArray);
182
183   Float_t   mult[64];  
184   Float_t    adc[64]; 
185   Float_t   time[64]; 
186   Float_t  width[64];
187   Bool_t  BBFlag[64];
188   Bool_t  BGFlag[64];
189    
190   for (Int_t i=0; i<64; i++){
191        adc[i]    = 0.0;
192        mult[i]   = 0.0;
193        time[i]   = 0.0;
194        width[i]  = 0.0;
195        BBFlag[i] = kFALSE;
196        BGFlag[i] = kFALSE;
197   }
198      
199   // loop over VZERO entries to get multiplicity
200   Int_t nEntries = (Int_t)digitsTree->GetEntries();
201   for (Int_t e=0; e<nEntries; e++) {
202     digitsTree->GetEvent(e);
203
204     Int_t nDigits = digitsArray->GetEntriesFast();
205     
206     for (Int_t d=0; d<nDigits; d++) {    
207         AliVZEROdigit* digit = (AliVZEROdigit*)digitsArray->At(d);      
208         Int_t  pmNumber      = digit->PMNumber(); 
209         // Pedestal retrieval and suppression: 
210         Float_t  pedestal      = fCalibData->GetPedestal(d);
211         adc[pmNumber]   =  digit->ADC() - pedestal; 
212         time[pmNumber]  =  digit->Time();
213         width[pmNumber] =  digit->Width();
214         BBFlag[pmNumber]=  digit->BBFlag();
215         BGFlag[pmNumber]=  digit->BGFlag();
216         // printf("PM = %d,  MIP per ADC channel = %f \n",pmNumber, fCalibData->GetMIPperADC(pmNumber));
217                 //AliInfo(Form("PM = %d,  ADC = %f TDC %f",pmNumber, digit->ADC(),digit->Time()));
218         // cut of ADC at 1MIP/2 
219         if(fCollisionMode >0) { 
220            Float_t MIP = 2.0;  
221            if (adc[pmNumber] > (MIP/2.) ) mult[pmNumber] += adc[pmNumber]*(1.0/MIP) ;
222            }
223            else{    
224            if (adc[pmNumber] > (1.0/fCalibData->GetMIPperADC(pmNumber) /2.) ) 
225                mult[pmNumber] += adc[pmNumber]*fCalibData->GetMIPperADC(pmNumber);
226         }           
227     } // end of loop over digits
228   } // end of loop over events in digits tree
229          
230   fESDVZERO->SetMultiplicity(mult);
231   fESDVZERO->SetADC(adc);
232   fESDVZERO->SetTime(time);
233   fESDVZERO->SetWidth(width);
234   fESDVZERO->SetBBFlag(BBFlag);
235   fESDVZERO->SetBGFlag(BGFlag);
236
237   // now get the trigger mask
238
239   AliVZEROTriggerMask *TriggerMask = new AliVZEROTriggerMask();
240   TriggerMask->SetAdcThreshold(10.0/2.0);
241   TriggerMask->SetTimeWindowWidthBBA(50);
242   TriggerMask->SetTimeWindowWidthBGA(20);
243   TriggerMask->SetTimeWindowWidthBBC(50);
244   TriggerMask->SetTimeWindowWidthBGC(20);
245   TriggerMask->FillMasks(digitsTree,digitsArray);
246
247   fESDVZERO->SetBBtriggerV0A(TriggerMask->GetBBtriggerV0A());
248   fESDVZERO->SetBGtriggerV0A(TriggerMask->GetBGtriggerV0A());
249   fESDVZERO->SetBBtriggerV0C(TriggerMask->GetBBtriggerV0C());
250   fESDVZERO->SetBGtriggerV0C(TriggerMask->GetBGtriggerV0C());
251   
252   if (esd) { 
253      AliDebug(1, Form("Writing VZERO data to ESD tree"));
254      esd->SetVZEROData(fESDVZERO);
255   }
256
257   if (esd) {
258      AliESDfriend *fr = (AliESDfriend*)esd->FindListObject("AliESDfriend");
259      if (fr) {
260         AliDebug(1, Form("Writing VZERO friend data to ESD tree"));
261         fr->SetVZEROfriend(fESDVZEROfriend);
262     }
263   }
264 }
265
266 //_____________________________________________________________________________
267 AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri) 
268 {
269 // Sets the storage  
270
271   Bool_t deleteManager = kFALSE;
272   
273   AliCDBManager *manager = AliCDBManager::Instance();
274   AliCDBStorage *defstorage = manager->GetDefaultStorage();
275   
276   if(!defstorage || !(defstorage->Contains("VZERO"))){ 
277      AliWarning("No default storage set or default storage doesn't contain VZERO!");
278      manager->SetDefaultStorage(uri);
279      deleteManager = kTRUE;
280   }
281  
282   AliCDBStorage *storage = manager->GetDefaultStorage();
283
284   if(deleteManager){
285      AliCDBManager::Instance()->UnsetDefaultStorage();
286      defstorage = 0;   // the storage is killed by AliCDBManager::Instance()->Destroy()
287   }
288
289   return storage; 
290 }
291
292 //____________________________________________________________________________
293 void AliVZEROReconstructor::GetCollisionMode()
294 {
295 // Retrieves the collision mode from GRP data
296
297 // Initialization of the GRP entry 
298   
299    Int_t run = AliCDBManager::Instance()->GetRun();
300   
301 //   printf("\n ++++++ Run Number retrieved as %d \n",run);
302   
303    AliCDBEntry*  entry = AliCDBManager::Instance()->Get("GRP/GRP/Data",run);
304    AliGRPObject* grpData = 0x0;
305    
306   if(entry){
307     TMap* m = dynamic_cast<TMap*>(entry->GetObject());  // old GRP entry
308     if(m){
309        m->Print();
310        grpData = new AliGRPObject();
311        grpData->ReadValuesFromMap(m);
312     }
313     else{
314        grpData = dynamic_cast<AliGRPObject*>(entry->GetObject());  // new GRP entry
315        entry->SetOwner(0);
316     }
317     AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
318   }
319
320    if(!grpData) { AliError("No GRP entry found in OCDB!");
321                   return; }
322
323 // Retrieval of simulated collision mode 
324
325   TString beamType = grpData->GetBeamType();
326   if(beamType==AliGRPObject::GetInvalidString()){
327      AliError("GRP/GRP/Data entry:  missing value for the beam type !");
328      AliError("\t VZERO cannot retrieve beam type\n");
329      return;
330   }
331
332    if( (beamType.CompareTo("P-P") ==0)  || (beamType.CompareTo("p-p") ==0) ){
333        fCollisionMode=0;
334   }
335    else if( (beamType.CompareTo("Pb-Pb") ==0)  || (beamType.CompareTo("A-A") ==0) ){
336        fCollisionMode=1;
337    }
338     
339   fBeamEnergy = grpData->GetBeamEnergy();
340   if(fBeamEnergy==AliGRPObject::GetInvalidFloat()) {
341      AliError("GRP/GRP/Data entry:  missing value for the beam energy ! Using 0");
342      fBeamEnergy = 0.;
343   }
344   
345 //    printf("\n ++++++ Beam type and collision mode retrieved as %s %d @ %1.3f GeV ++++++\n\n",beamType.Data(), fCollisionMode, fBeamEnergy);
346
347 }
348
349 //_____________________________________________________________________________
350 AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
351 {
352   // Gets calibration object for VZERO set
353
354   AliCDBManager *man = AliCDBManager::Instance();
355
356   AliCDBEntry *entry=0;
357
358   entry = man->Get("VZERO/Calib/Data");
359
360 //   if(!entry){
361 //     AliWarning("Load of calibration data from default storage failed!");
362 //     AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
363 //     Int_t runNumber = man->GetRun();
364 //     entry = man->GetStorage("local://$ALICE_ROOT/OCDB")
365 //       ->Get("VZERO/Calib/Data",runNumber);
366 //      
367 //   }
368
369   // Retrieval of data in directory VZERO/Calib/Data:
370
371   AliVZEROCalibData *calibdata = 0;
372
373   if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
374   if (!calibdata)  AliFatal("No calibration data from calibration database !");
375
376   return calibdata;
377 }
378