1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 /// class for VZERO reconstruction //
22 ///////////////////////////////////////////////////////////////////////////////
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"
38 ClassImp(AliVZEROReconstructor)
40 //_____________________________________________________________________________
41 AliVZEROReconstructor:: AliVZEROReconstructor(): AliReconstructor(),
45 fCalibData(GetCalibData()),
49 // Default constructor
50 // Get calibration data
52 // fCalibData = GetCalibData();
57 //_____________________________________________________________________________
58 AliVZEROReconstructor& AliVZEROReconstructor::operator =
59 (const AliVZEROReconstructor& /*reconstructor*/)
61 // assignment operator
63 Fatal("operator =", "assignment operator not implemented");
67 //_____________________________________________________________________________
68 AliVZEROReconstructor::~AliVZEROReconstructor()
73 delete fESDVZEROfriend;
76 //_____________________________________________________________________________
77 void AliVZEROReconstructor::Init()
81 fESDVZERO = new AliESDVZERO;
82 fESDVZEROfriend = new AliESDVZEROfriend;
84 GetCollisionMode(); // fCollisionMode =1 for Pb-Pb simulated data
87 //______________________________________________________________________
88 void AliVZEROReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
90 // converts RAW to digits - pedestal is subtracted
93 AliError("No digits tree!");
97 TClonesArray* digitsArray = new TClonesArray("AliVZEROdigit");
98 digitsTree->Branch("VZERODigit", &digitsArray);
100 fESDVZEROfriend->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:
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);
118 // Convert i (FEE channel numbering) to j (aliroot channel numbering)
119 Int_t j = rawStream.GetOfflineChannel(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);
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));
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));
142 fESDVZEROfriend->SetTime(j,rawStream.GetTime(i));
143 fESDVZEROfriend->SetWidth(j,rawStream.GetWidth(i));
146 // Filling the esd friend object
147 fESDVZEROfriend->SetTriggerInputs(rawStream.GetTriggerInputs());
148 fESDVZEROfriend->SetTriggerInputsMask(rawStream.GetTriggerInputsMask());
150 for(Int_t iScaler = 0; iScaler < AliESDVZEROfriend::kNScalers; iScaler++)
151 fESDVZEROfriend->SetTriggerScalers(iScaler,rawStream.GetTriggerScalers(iScaler));
153 for(Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++)
154 fESDVZEROfriend->SetBunchNumbersMB(iBunch,rawStream.GetBunchNumbersMB(iBunch));
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]);
167 //______________________________________________________________________
168 void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
169 AliESDEvent* esd) const
171 // fills multiplicities to the ESD
174 AliError("No digits tree!");
178 TClonesArray* digitsArray = NULL;
179 TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
180 digitBranch->SetAddress(&digitsArray);
189 for (Int_t i=0; i<64; i++){
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);
203 Int_t nDigits = digitsArray->GetEntriesFast();
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 Float_t pedestal = fCalibData->GetPedestal(d);
210 adc[pmNumber] = digit->ADC() - pedestal;
211 time[pmNumber] = digit->Time();
212 width[pmNumber] = 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 = %f TDC %f",pmNumber, digit->ADC(),digit->Time()));
217 // cut of ADC at 1MIP/2
218 if(fCollisionMode >0) {
220 if (adc[pmNumber] > (MIP/2.) ) mult[pmNumber] += adc[pmNumber]*(1.0/MIP) ;
223 if (adc[pmNumber] > (1.0/fCalibData->GetMIPperADC(pmNumber) /2.) )
224 mult[pmNumber] += adc[pmNumber]*fCalibData->GetMIPperADC(pmNumber);
226 } // end of loop over digits
227 } // end of loop over events in digits tree
229 fESDVZERO->SetMultiplicity(mult);
230 fESDVZERO->SetADC(adc);
231 fESDVZERO->SetTime(time);
232 fESDVZERO->SetWidth(width);
233 fESDVZERO->SetBBFlag(BBFlag);
234 fESDVZERO->SetBGFlag(BGFlag);
236 // now get the trigger mask
238 AliVZEROTriggerMask *TriggerMask = new AliVZEROTriggerMask();
239 TriggerMask->SetAdcThreshold(10.0/2.0);
240 TriggerMask->SetTimeWindowWidthBBA(50);
241 TriggerMask->SetTimeWindowWidthBGA(20);
242 TriggerMask->SetTimeWindowWidthBBC(50);
243 TriggerMask->SetTimeWindowWidthBGC(20);
244 TriggerMask->FillMasks(digitsTree,digitsArray);
246 fESDVZERO->SetBBtriggerV0A(TriggerMask->GetBBtriggerV0A());
247 fESDVZERO->SetBGtriggerV0A(TriggerMask->GetBGtriggerV0A());
248 fESDVZERO->SetBBtriggerV0C(TriggerMask->GetBBtriggerV0C());
249 fESDVZERO->SetBGtriggerV0C(TriggerMask->GetBGtriggerV0C());
252 AliDebug(1, Form("Writing VZERO data to ESD tree"));
253 esd->SetVZEROData(fESDVZERO);
257 AliESDfriend *fr = (AliESDfriend*)esd->FindListObject("AliESDfriend");
259 AliDebug(1, Form("Writing VZERO friend data to ESD tree"));
260 fr->SetVZEROfriend(fESDVZEROfriend);
265 //_____________________________________________________________________________
266 AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri)
270 Bool_t deleteManager = kFALSE;
272 AliCDBManager *manager = AliCDBManager::Instance();
273 AliCDBStorage *defstorage = manager->GetDefaultStorage();
275 if(!defstorage || !(defstorage->Contains("VZERO"))){
276 AliWarning("No default storage set or default storage doesn't contain VZERO!");
277 manager->SetDefaultStorage(uri);
278 deleteManager = kTRUE;
281 AliCDBStorage *storage = manager->GetDefaultStorage();
284 AliCDBManager::Instance()->UnsetDefaultStorage();
285 defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
291 //____________________________________________________________________________
292 void AliVZEROReconstructor::GetCollisionMode()
294 // Retrieves the collision mode from GRP data
296 // Initialization of the GRP entry
297 // To be replace by a call to AliRunInfo object
299 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
300 AliGRPObject* grpData = 0x0;
303 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
305 grpData = new AliGRPObject();
306 grpData->ReadValuesFromMap(m);
309 grpData = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
313 if(!grpData) { AliError("No GRP entry found in OCDB!");
316 // Retrieval of simulated collision mode
318 TString beamType = grpData->GetBeamType();
319 if(beamType==AliGRPObject::GetInvalidString()){
320 AliError("GRP/GRP/Data entry: missing value for the beam type !");
321 AliError("\t VZERO cannot retrieve beam type\n");
325 if( (beamType.CompareTo("P-P") ==0) || (beamType.CompareTo("p-p") ==0) ){
328 else if( (beamType.CompareTo("Pb-Pb") ==0) || (beamType.CompareTo("A-A") ==0) ){
332 fBeamEnergy = grpData->GetBeamEnergy();
333 if(fBeamEnergy==AliGRPObject::GetInvalidFloat()) {
334 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
338 // printf("\n ++++++ Beam type and collision mode retrieved as %s %d @ %1.3f GeV ++++++\n\n",beamType.Data(), fCollisionMode, fBeamEnergy);
342 //_____________________________________________________________________________
343 AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
345 // Gets calibration object for VZERO set
347 AliCDBManager *man = AliCDBManager::Instance();
349 AliCDBEntry *entry=0;
351 entry = man->Get("VZERO/Calib/Data");
354 // AliWarning("Load of calibration data from default storage failed!");
355 // AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
356 // Int_t runNumber = man->GetRun();
357 // entry = man->GetStorage("local://$ALICE_ROOT/OCDB")
358 // ->Get("VZERO/Calib/Data",runNumber);
362 // Retrieval of data in directory VZERO/Calib/Data:
364 AliVZEROCalibData *calibdata = 0;
366 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
367 if (!calibdata) AliFatal("No calibration data from calibration database !");