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 ///////////////////////////////////////////////////////////////////////////
21 // This class contains the base procedures for the VZERO detector //
22 // Default geometry of November 2003 : V0R box is 4.4 cm thick //
23 // scintillators are 2 cm thick //
24 // All comments should be sent to Brigitte CHEYNIS : //
25 // b.cheynis@ipnl.in2p3.fr //
28 ///////////////////////////////////////////////////////////////////////////
31 // --- Standard libraries ---
32 #include <Riostream.h>
35 // --- ROOT libraries ---
43 #include "TClonesArray.h"
44 #include "TStopwatch.h"
45 #include "TParameter.h"
48 // --- AliRoot header files ---
52 #include "AliVZEROLoader.h"
53 #include "AliVZERODigitizer.h"
54 #include "AliVZEROBuffer.h"
55 #include "AliRunDigitizer.h"
56 #include "AliVZEROdigit.h"
57 #include "AliVZEROSDigit.h"
59 #include "AliRawReader.h"
60 #include "AliCDBManager.h"
61 #include "AliCDBEntry.h"
62 #include "AliVZERORawStream.h"
63 #include "AliVZEROCalibData.h"
64 #include "AliVZERORecoParam.h"
65 #include "AliVZEROReconstructor.h"
68 //__________________________________________________________________
69 AliVZERO::AliVZERO(): AliDetector(),
82 /// Default Constructor
84 AliDebug(1,Form("default (empty) ctor this=%p",this));
87 for(Int_t i = 0 ; i < 64; ++i) {
93 //_____________________________________________________________________________
94 AliVZERO::AliVZERO(const char *name, const char *title)
95 : AliDetector(name,title),
109 // Standard constructor for VZERO Detector
111 AliDebug(1,Form("ctor this=%p",this));
113 // fIshunt = 1; // All hits are associated with primary particles
115 fHits = new TClonesArray("AliVZEROhit", 400);
116 fDigits = new TClonesArray("AliVZEROdigit",400);
118 gAlice->GetMCApp()->AddHitList(fHits);
120 // fThickness = 4.4; // total thickness of the V0R box in cm
121 // fThickness1 = 2.0; // thickness of scintillating cells in cm
123 // fMaxStepQua = 0.05;
124 // fMaxStepAlu = 0.01;
126 // fMaxDestepQua = -1.0;
127 // fMaxDestepAlu = -1.0;
129 for(Int_t i = 0 ; i < 64; ++i) {
135 //_____________________________________________________________________________
136 AliVZERO::~AliVZERO()
139 // Default destructor for VZERO Detector
161 //_____________________________________________________________________________
162 void AliVZERO::CreateGeometry()
165 // Builds simple Geant3 geometry
168 //_____________________________________________________________________________
169 void AliVZERO::CreateMaterials()
172 // Creates materials used for Geant3 geometry
176 //_____________________________________________________________________________
177 void AliVZERO::Init()
180 // Initialises the VZERO class after it has been built
185 //_____________________________________________________________________________
186 void AliVZERO::SetMaxStepQua(Float_t p1)
189 // Possible parametrisation of steps in active materials
194 //_____________________________________________________________________________
195 void AliVZERO::SetMaxStepAlu(Float_t p1)
198 // Possible parametrisation of steps in Aluminum foils (not used in
204 //_____________________________________________________________________________
205 void AliVZERO::SetMaxDestepQua(Float_t p1)
208 // Possible parametrisation of steps in active materials (quartz)
213 //_____________________________________________________________________________
214 void AliVZERO::SetMaxDestepAlu(Float_t p1)
217 // Possible parametrisation of steps in Aluminum (not used in
223 //_____________________________________________________________________________
224 AliLoader* AliVZERO::MakeLoader(const char* topfoldername)
227 // Builds VZEROgetter (AliLoader type)
228 // if detector wants to use customized getter, it must overload this method
230 // Info("MakeLoader","Creating AliVZEROLoader. Top folder is %s.",topfoldername);
232 AliDebug(1,Form("Creating AliVZEROLoader, Top folder is %s ",topfoldername));
233 fLoader = new AliVZEROLoader(GetName(),topfoldername);
237 //_____________________________________________________________________________
238 void AliVZERO::SetTreeAddress()
241 // Sets tree address for hits.
243 if (fLoader->TreeH() && (fHits == 0x0))
244 fHits = new TClonesArray("AliVZEROhit", 400);
246 AliDetector::SetTreeAddress();
249 //_____________________________________________________________________________
250 AliDigitizer* AliVZERO::CreateDigitizer(AliRunDigitizer* manager) const
253 // Creates a digitizer for VZERO
255 return new AliVZERODigitizer(manager);
258 //_____________________________________________________________________________
259 void AliVZERO::Hits2Digits(){
261 // Converts hits to digits
263 // Creates the VZERO digitizer
264 AliVZERODigitizer* dig = new AliVZERODigitizer(this,AliVZERODigitizer::kHits2Digits);
266 // Creates the digits
271 //_____________________________________________________________________________
272 void AliVZERO::Hits2SDigits(){
274 // Converts hits to summable digits
276 // Creates the VZERO digitizer
277 AliVZERODigitizer* dig = new AliVZERODigitizer(this,AliVZERODigitizer::kHits2SDigits);
279 // Creates the sdigits
284 //_____________________________________________________________________________
285 void AliVZERO::Digits2Raw()
288 // Converts digits of the current event to raw data
291 AliVZERO *fVZERO = (AliVZERO*)gAlice->GetDetector("VZERO");
292 fLoader->LoadDigits();
293 TTree* digits = fLoader->TreeD();
295 Error("Digits2Raw", "no digits tree");
298 TClonesArray * VZEROdigits = new TClonesArray("AliVZEROdigit",1000);
299 fVZERO->SetTreeAddress();
300 digits->GetBranch("VZERODigit")->SetAddress(&VZEROdigits);
302 const char *fileName = AliDAQ::DdlFileName("VZERO",0);
303 AliVZEROBuffer* buffer = new AliVZEROBuffer(fileName);
305 // Get Trigger information first
306 // Read trigger inputs from trigger-detector object
307 AliDataLoader * dataLoader = fLoader->GetDigitsDataLoader();
308 if( !dataLoader->IsFileOpen() )
309 dataLoader->OpenFile( "READ" );
310 AliTriggerDetector* trgdet = (AliTriggerDetector*)dataLoader->GetDirectory()->Get( "Trigger" );
311 UInt_t triggerInfo = 0;
313 triggerInfo = trgdet->GetMask() & 0xffff;
316 AliError(Form("There is no trigger object for %s",fLoader->GetName()));
319 buffer->WriteTriggerInfo((UInt_t)triggerInfo);
320 buffer->WriteTriggerScalers();
321 buffer->WriteBunchNumbers();
323 Int_t aBBflagsV0A = 0;
324 Int_t aBBflagsV0C = 0;
325 Int_t aBGflagsV0A = 0;
326 Int_t aBGflagsV0C = 0;
328 if (digits->GetUserInfo()->FindObject("BBflagsV0A")) {
329 aBBflagsV0A = ((TParameter<int>*)digits->GetUserInfo()->FindObject("BBflagsV0A"))->GetVal();
332 AliWarning("V0A beam-beam flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
334 if (digits->GetUserInfo()->FindObject("BBflagsV0C")) {
335 aBBflagsV0C = ((TParameter<int>*)digits->GetUserInfo()->FindObject("BBflagsV0C"))->GetVal();
338 AliWarning("V0C beam-beam flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
340 if (digits->GetUserInfo()->FindObject("BGflagsV0A")) {
341 aBGflagsV0A = ((TParameter<int>*)digits->GetUserInfo()->FindObject("BGflagsV0A"))->GetVal();
344 AliWarning("V0A beam-gas flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
346 if (digits->GetUserInfo()->FindObject("BGflagsV0C")) {
347 aBGflagsV0C = ((TParameter<int>*)digits->GetUserInfo()->FindObject("BGflagsV0C"))->GetVal();
350 AliWarning("V0C beam-gas flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
352 // Now retrieve the channel information: charge smaples + time and
353 // dump it into ADC and Time arrays
354 Int_t nEntries = Int_t(digits->GetEntries());
355 Short_t aADC[64][AliVZEROdigit::kNClocks];
358 Bool_t aIntegrator[64];
362 for (Int_t i = 0; i < nEntries; i++) {
363 fVZERO->ResetDigits();
365 Int_t ndig = VZEROdigits->GetEntriesFast();
367 if(ndig == 0) continue;
368 for(Int_t k=0; k<ndig; k++){
369 AliVZEROdigit* fVZERODigit = (AliVZEROdigit*) VZEROdigits->At(k);
370 // Convert aliroot channel k into FEE channel iChannel before writing data
371 Int_t iChannel = AliVZEROCalibData::GetBoardNumber(fVZERODigit->PMNumber()) * 8 +
372 AliVZEROCalibData::GetFEEChannelNumber(fVZERODigit->PMNumber());
373 for(Int_t iClock = 0; iClock < AliVZEROdigit::kNClocks; ++iClock) aADC[iChannel][iClock] = fVZERODigit->ChargeADC(iClock);
374 aTime[iChannel] = fVZERODigit->Time();
375 aWidth[iChannel] = fVZERODigit->Width();
376 aIntegrator[iChannel]= fVZERODigit->Integrator();
377 if(fVZERODigit->PMNumber() < 32) {
378 aBBflag[iChannel] = (aBBflagsV0C >> fVZERODigit->PMNumber()) & 0x1;
379 aBGflag[iChannel] = (aBGflagsV0C >> fVZERODigit->PMNumber()) & 0x1;
382 aBBflag[iChannel] = (aBBflagsV0A >> (fVZERODigit->PMNumber()-32)) & 0x1;
383 aBGflag[iChannel] = (aBGflagsV0A >> (fVZERODigit->PMNumber()-32)) & 0x1;
385 AliDebug(1,Form("DDL: %s\tdigit number: %d\tPM number: %d\tADC: %d\tTime: %f",
386 fileName,k,fVZERODigit->PMNumber(),aADC[iChannel][AliVZEROdigit::kNClocks/2],aTime[iChannel]));
392 for (Int_t iCIU = 0; iCIU < 8; iCIU++) {
394 // decoding of one Channel Interface Unit numbered iCIU - there are 8 channels per CIU (and 8 CIUs) :
396 for(Int_t iChannel_Offset = iCIU*8; iChannel_Offset < (iCIU*8)+8; iChannel_Offset=iChannel_Offset+4) {
397 for(Int_t iChannel = iChannel_Offset; iChannel < iChannel_Offset+4; iChannel++) {
398 buffer->WriteChannel(iChannel, aADC[iChannel], aIntegrator[iChannel]);
400 buffer->WriteBeamFlags(&aBBflag[iChannel_Offset],&aBGflag[iChannel_Offset]);
401 buffer->WriteMBInfo();
402 buffer->WriteMBFlags();
403 buffer->WriteBeamScalers();
406 for(Int_t iChannel = iCIU*8 + 7; iChannel >= iCIU*8; iChannel--) {
407 buffer->WriteTiming(aTime[iChannel], aWidth[iChannel]);
410 // End of decoding of one CIU card
412 } // end of decoding the eight CIUs
415 fLoader->UnloadDigits();
418 //_____________________________________________________________________________
419 Bool_t AliVZERO::Raw2SDigits(AliRawReader* rawReader){
420 // Converts the VZERO raw data into digits
421 // The method is used for merging simulated and
427 AliError("no VZERO loader found");
430 fLoader->LoadSDigits("UPDATE");
432 if (!fLoader->TreeS()) fLoader->MakeTree("S");
433 fLoader->MakeSDigitsContainer();
434 TTree* treeS = fLoader->TreeS();
436 TClonesArray *sdigits = new TClonesArray("AliVZEROSDigit", 64);
437 treeS->Branch("VZEROSDigit", &sdigits);
441 AliVZERORawStream rawStream(rawReader);
443 if (!rawStream.Next()) return kFALSE; // No VZERO data found
448 Float_t *charges = NULL;
450 for(Int_t iChannel=0; iChannel < 64; ++iChannel) {
451 Int_t offlineCh = rawStream.GetOfflineChannel(iChannel);
452 Short_t chargeADC[AliVZEROdigit::kNClocks];
453 for(Int_t iClock=0; iClock < AliVZEROdigit::kNClocks; ++iClock) {
454 chargeADC[iClock] = rawStream.GetPedestal(iChannel,iClock);
457 Bool_t integrator = rawStream.GetIntegratorFlag(iChannel,AliVZEROdigit::kNClocks/2);
458 // HPTDC data (leading time and width)
459 Int_t board = AliVZEROCalibData::GetBoardNumber(offlineCh);
460 Float_t time = rawStream.GetTime(iChannel)*fCalibData->GetTimeResolution(board);
461 // Float_t width = rawStream.GetWidth(iChannel)*fCalibData->GetWidthResolution(board);
464 // Pedestal retrieval and suppression
467 Float_t adcPedSub[AliVZEROdigit::kNClocks];
468 Float_t integral = fSignalShape->Integral(0,200);
469 for(Int_t iClock=0; iClock < AliVZEROdigit::kNClocks; ++iClock) {
470 Bool_t iIntegrator = (iClock%2 == 0) ? integrator : !integrator;
471 Int_t k = offlineCh + 64*iIntegrator;
472 adcPedSub[iClock] = (Float_t)chargeADC[iClock] - fCalibData->GetPedestal(k);
473 if(adcPedSub[iClock] <= fRecoParam->GetNSigmaPed()*fCalibData->GetSigma(k)) {
474 adcPedSub[iClock] = 0;
477 if(iClock < fRecoParam->GetStartClock() || iClock > fRecoParam->GetEndClock()) continue;
478 if(adcPedSub[iClock] > maxadc) {
479 maxadc = adcPedSub[iClock];
484 Int_t start = imax - fRecoParam->GetNPreClocks();
485 if (start < 0) start = 0;
486 Int_t end = imax + fRecoParam->GetNPostClocks();
487 if (end > 20) end = 20;
488 for(Int_t iClock = start; iClock <= end; iClock++) {
489 adc += adcPedSub[iClock];
492 Float_t correctedTime = CorrectLeadingTime(offlineCh,time,adc);
495 nbins = fNBins[offlineCh];
496 charges = new Float_t[nbins];
498 else if (nbins != fNBins[offlineCh]) {
500 nbins = fNBins[offlineCh];
501 charges = new Float_t[nbins];
503 memset(charges,0,nbins*sizeof(Float_t));
505 // Now lets produce SDigit
506 if ((correctedTime > (AliVZEROReconstructor::kInvalidTime + 1e-6)) &&
508 for(Int_t iBin = 0; iBin < nbins; ++iBin) {
509 Float_t t = fBinSize[offlineCh]*Float_t(iBin);
510 if ((t < correctedTime) ||
511 (t > (correctedTime+200.))) continue;
512 charges[iBin] = kChargePerADC*adc*(fSignalShape->Eval(t-correctedTime)*fBinSize[offlineCh]/integral);
516 TClonesArray &sdigitsref = *sdigits;
517 new (sdigitsref[nSDigits++]) AliVZEROSDigit(offlineCh,fNBins[offlineCh],charges);
519 if (charges) delete [] charges;
523 fLoader->WriteSDigits("OVERWRITE");
524 fLoader->UnloadSDigits();
531 //_____________________________________________________________________________
532 void AliVZERO::GetCalibData()
534 // Gets calibration object for VZERO set
535 // Do nothing in case it is already loaded
536 if (fCalibData) return;
538 AliCDBEntry *entry = AliCDBManager::Instance()->Get("VZERO/Calib/Data");
539 if (entry) fCalibData = (AliVZEROCalibData*) entry->GetObject();
540 if (!fCalibData) AliFatal("No calibration data from calibration database !");
542 AliCDBEntry *entry2 = AliCDBManager::Instance()->Get("VZERO/Calib/TimeSlewing");
543 if (!entry2) AliFatal("VZERO time slewing function is not found in OCDB !");
544 fTimeSlewing = (TF1*)entry2->GetObject();
546 for(Int_t i = 0 ; i < 64; ++i) {
547 Int_t board = AliVZEROCalibData::GetBoardNumber(i);
548 fNBins[i] = TMath::Nint(((Float_t)(fCalibData->GetMatchWindow(board)+1)*25.0+
549 (Float_t)kMaxTDCWidth*fCalibData->GetWidthResolution(board))/
550 fCalibData->GetTimeResolution(board));
551 fBinSize[i] = fCalibData->GetTimeResolution(board);
554 fSignalShape = new TF1("VZEROSDigitSignalShape",this,&AliVZERO::SignalShape,0,200,6,"AliVZERO","SignalShape");
555 fSignalShape->SetParameters(0,1.57345e1,-4.25603e-1,
556 2.9,6.40982,3.69339e-01);
558 fRecoParam = new AliVZERORecoParam;
563 Float_t AliVZERO::CorrectLeadingTime(Int_t i, Float_t time, Float_t adc) const
565 // Correct the leading time
566 // for slewing effect and
567 // misalignment of the channels
568 if (time < 1e-6) return -1024;
570 // In case of pathological signals
571 if (adc < 1e-6) return time;
573 // Slewing correction
574 Float_t thr = fCalibData->GetCalibDiscriThr(i,kTRUE);
575 time -= fTimeSlewing->Eval(adc/thr);
580 double AliVZERO::SignalShape(double *x, double *par)
582 // this function simulates the signal
583 // shape used in Raw->SDigits method
586 if (xx <= par[0]) return 0;
587 Double_t a = 1./TMath::Power((xx-par[0])/par[1],1./par[2]);
588 if (xx <= par[3]) return a;
589 Double_t b = 1./TMath::Power((xx-par[3])/par[4],1./par[5]);
590 Double_t f = a*b/(a+b);
591 AliDebug(100,Form("x=%f func=%f",xx,f));