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