]> git.uio.no Git - u/mrichter/AliRoot.git/blame - VZERO/AliVZERO.cxx
use Terminate function for producing summary plots (Markus)
[u/mrichter/AliRoot.git] / VZERO / AliVZERO.cxx
CommitLineData
47890cd3 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
88cb7938 16/* $Id$ */
47890cd3 17
18///////////////////////////////////////////////////////////////////////////
19// //
20// V-Zero Detector //
21// This class contains the base procedures for the VZERO detector //
b0d2c2d3 22// Default geometry of November 2003 : V0R box is 4.4 cm thick //
23// scintillators are 2 cm thick //
47890cd3 24// All comments should be sent to Brigitte CHEYNIS : //
61874e87 25// b.cheynis@ipnl.in2p3.fr //
26// //
47890cd3 27// //
28///////////////////////////////////////////////////////////////////////////
29
88cb7938 30
b2501ea3 31// --- Standard libraries ---
3af027ba 32#include <Riostream.h>
b0d2c2d3 33#include <stdlib.h>
47890cd3 34
b2501ea3 35// --- ROOT libraries ---
36#include <TNamed.h>
b0d2c2d3 37#include "TROOT.h"
38#include "TFile.h"
39#include "TNetFile.h"
40#include "TRandom.h"
41#include "TTree.h"
42#include "TBranch.h"
43#include "TClonesArray.h"
44#include "TStopwatch.h"
b6fd9c4a 45#include "TParameter.h"
b2501ea3 46
47// --- AliRoot header files ---
48#include "AliRun.h"
49#include "AliMC.h"
47890cd3 50#include "AliVZERO.h"
b2501ea3 51#include "AliVZEROLoader.h"
b0d2c2d3 52#include "AliVZERODigitizer.h"
53#include "AliVZEROBuffer.h"
54#include "AliRunDigitizer.h"
55#include "AliVZEROdigit.h"
362c9d61 56#include "AliDAQ.h"
20a489c2 57#include "AliRawReader.h"
58#include "AliVZERORawStream.h"
b6fd9c4a 59#include "AliVZEROCalibData.h"
47890cd3 60
61ClassImp(AliVZERO)
0b2bea8b 62 //__________________________________________________________________
63AliVZERO::AliVZERO(): AliDetector(),
64 fIdSens1(0),
65 fThickness(0.),
66 fThickness1(0.),
67 fMaxStepQua(0.),
68 fMaxStepAlu(0.),
69 fMaxDestepQua(0.),
70 fMaxDestepAlu(0.)
71{
72/// Default Constructor
73
74 AliDebug(1,Form("default (empty) ctor this=%p",this));
75 fIshunt = 0;
76}
47890cd3 77//_____________________________________________________________________________
78AliVZERO::AliVZERO(const char *name, const char *title)
0b2bea8b 79 : AliDetector(name,title),
80 fIdSens1(0),
81 fThickness(4.4),
82 fThickness1(2.0),
83 fMaxStepQua(0.05),
84 fMaxStepAlu(0.01),
85 fMaxDestepQua(-1.0),
86 fMaxDestepAlu(-1.0)
47890cd3 87{
0b2bea8b 88
47890cd3 89 // Standard constructor for VZERO Detector
0b2bea8b 90
91 AliDebug(1,Form("ctor this=%p",this));
47890cd3 92
b0d2c2d3 93 // fIshunt = 1; // All hits are associated with primary particles
47890cd3 94
61874e87 95 fHits = new TClonesArray("AliVZEROhit", 400);
96 fDigits = new TClonesArray("AliVZEROdigit",400);
97
5d12ce38 98 gAlice->GetMCApp()->AddHitList(fHits);
61874e87 99
0b2bea8b 100// fThickness = 4.4; // total thickness of the V0R box in cm
101// fThickness1 = 2.0; // thickness of scintillating cells in cm
102//
103// fMaxStepQua = 0.05;
104// fMaxStepAlu = 0.01;
105//
106// fMaxDestepQua = -1.0;
107// fMaxDestepAlu = -1.0;
47890cd3 108
47890cd3 109
61874e87 110}
111
112//_____________________________________________________________________________
113AliVZERO::~AliVZERO()
114{
b2501ea3 115 //
116 // Default destructor for VZERO Detector
117 //
118
61874e87 119 if (fHits) {
120 fHits->Delete();
121 delete fHits;
b0d2c2d3 122 fHits=0; }
b2501ea3 123
124 if (fDigits) {
125 fDigits->Delete();
126 delete fDigits;
b0d2c2d3 127 fDigits=0; }
61874e87 128}
47890cd3 129
47890cd3 130//_____________________________________________________________________________
131void AliVZERO::CreateGeometry()
132{
133 //
b2501ea3 134 // Builds simple Geant3 geometry
47890cd3 135 //
136}
137//_____________________________________________________________________________
138void AliVZERO::CreateMaterials()
139{
140 //
b2501ea3 141 // Creates materials used for Geant3 geometry
47890cd3 142 //
143}
61874e87 144
47890cd3 145//_____________________________________________________________________________
47890cd3 146void AliVZERO::Init()
147{
148 //
b2501ea3 149 // Initialises the VZERO class after it has been built
47890cd3 150 //
151}
152
61874e87 153
b2501ea3 154//_____________________________________________________________________________
47890cd3 155void AliVZERO::SetMaxStepQua(Float_t p1)
156{
b2501ea3 157 //
158 // Possible parametrisation of steps in active materials
159 //
47890cd3 160 fMaxStepQua = p1;
161}
162
b2501ea3 163//_____________________________________________________________________________
47890cd3 164void AliVZERO::SetMaxStepAlu(Float_t p1)
165{
b2501ea3 166 //
167 // Possible parametrisation of steps in Aluminum foils (not used in
168 // version v2)
169 //
47890cd3 170 fMaxStepAlu = p1;
171}
172
b2501ea3 173//_____________________________________________________________________________
47890cd3 174void AliVZERO::SetMaxDestepQua(Float_t p1)
175{
b2501ea3 176 //
177 // Possible parametrisation of steps in active materials (quartz)
178 //
47890cd3 179 fMaxDestepQua = p1;
180}
181
b2501ea3 182//_____________________________________________________________________________
47890cd3 183void AliVZERO::SetMaxDestepAlu(Float_t p1)
184{
b2501ea3 185 //
186 // Possible parametrisation of steps in Aluminum (not used in
187 // version v2)
188 //
47890cd3 189 fMaxDestepAlu = p1;
190}
4dbb3fd3 191
b2501ea3 192//_____________________________________________________________________________
4dbb3fd3 193AliLoader* AliVZERO::MakeLoader(const char* topfoldername)
194{
b2501ea3 195 //
196 // Builds VZEROgetter (AliLoader type)
4dbb3fd3 197 // if detector wants to use customized getter, it must overload this method
b2501ea3 198 //
3e87825e 199// Info("MakeLoader","Creating AliVZEROLoader. Top folder is %s.",topfoldername);
200
201 AliDebug(1,Form("Creating AliVZEROLoader, Top folder is %s ",topfoldername));
4dbb3fd3 202 fLoader = new AliVZEROLoader(GetName(),topfoldername);
203 return fLoader;
204}
205
b2501ea3 206//_____________________________________________________________________________
207void AliVZERO::SetTreeAddress()
208{
b0d2c2d3 209 //
0e305a84 210 // Sets tree address for hits.
b2501ea3 211 //
0e305a84 212 if (fLoader->TreeH() && (fHits == 0x0))
213 fHits = new TClonesArray("AliVZEROhit", 400);
214
215 AliDetector::SetTreeAddress();
216}
4dbb3fd3 217
b0d2c2d3 218//_____________________________________________________________________________
219AliDigitizer* AliVZERO::CreateDigitizer(AliRunDigitizer* manager) const
220{
221 //
222 // Creates a digitizer for VZERO
223 //
224 return new AliVZERODigitizer(manager);
225}
226
227//_____________________________________________________________________________
228void AliVZERO::Hits2Digits(){
229 //
72da5ce8 230 // Converts hits to digits
b0d2c2d3 231 //
72da5ce8 232 // Creates the VZERO digitizer
233 AliVZERODigitizer* dig = new AliVZERODigitizer(this,AliVZERODigitizer::kHits2Digits);
b0d2c2d3 234
72da5ce8 235 // Creates the digits
236 dig->Exec("");
237
238}
b0d2c2d3 239
72da5ce8 240//_____________________________________________________________________________
241void AliVZERO::Hits2SDigits(){
242 //
243 // Converts hits to summable digits
244 //
b0d2c2d3 245 // Creates the VZERO digitizer
72da5ce8 246 AliVZERODigitizer* dig = new AliVZERODigitizer(this,AliVZERODigitizer::kHits2SDigits);
b0d2c2d3 247
72da5ce8 248 // Creates the sdigits
b0d2c2d3 249 dig->Exec("");
250
251}
72da5ce8 252
b0d2c2d3 253//_____________________________________________________________________________
254void AliVZERO::Digits2Raw()
255{
c4f89fd4 256 //
257 // Converts digits of the current event to raw data
258 //
b0d2c2d3 259
c4f89fd4 260 AliVZERO *fVZERO = (AliVZERO*)gAlice->GetDetector("VZERO");
261 fLoader->LoadDigits();
262 TTree* digits = fLoader->TreeD();
263 if (!digits) {
264 Error("Digits2Raw", "no digits tree");
265 return;
266 }
267 TClonesArray * VZEROdigits = new TClonesArray("AliVZEROdigit",1000);
268 fVZERO->SetTreeAddress();
269 digits->GetBranch("VZERODigit")->SetAddress(&VZEROdigits);
b0d2c2d3 270
c4f89fd4 271 const char *fileName = AliDAQ::DdlFileName("VZERO",0);
272 AliVZEROBuffer* buffer = new AliVZEROBuffer(fileName);
b0d2c2d3 273
c4f89fd4 274 // Get Trigger information first
275 // Read trigger inputs from trigger-detector object
276 AliDataLoader * dataLoader = fLoader->GetDigitsDataLoader();
277 if( !dataLoader->IsFileOpen() )
278 dataLoader->OpenFile( "READ" );
279 AliTriggerDetector* trgdet = (AliTriggerDetector*)dataLoader->GetDirectory()->Get( "Trigger" );
280 UInt_t triggerInfo = 0;
281 if(trgdet) {
282 triggerInfo = trgdet->GetMask() & 0xffff;
283 }
284 else {
285 AliError(Form("There is no trigger object for %s",fLoader->GetName()));
286 }
b0d2c2d3 287
c4f89fd4 288 buffer->WriteTriggerInfo((UInt_t)triggerInfo);
289 buffer->WriteTriggerScalers();
290 buffer->WriteBunchNumbers();
291
b6fd9c4a 292 Int_t aBBflagsV0A = 0;
293 Int_t aBBflagsV0C = 0;
294 Int_t aBGflagsV0A = 0;
295 Int_t aBGflagsV0C = 0;
296
297 if (digits->GetUserInfo()->FindObject("BBflagsV0A")) {
298 aBBflagsV0A = ((TParameter<int>*)digits->GetUserInfo()->FindObject("BBflagsV0A"))->GetVal();
299 }
300 else
301 AliWarning("V0A beam-beam flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
302
303 if (digits->GetUserInfo()->FindObject("BBflagsV0C")) {
304 aBBflagsV0C = ((TParameter<int>*)digits->GetUserInfo()->FindObject("BBflagsV0C"))->GetVal();
305 }
306 else
307 AliWarning("V0C beam-beam flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
726d762c 308
b6fd9c4a 309 if (digits->GetUserInfo()->FindObject("BGflagsV0A")) {
310 aBGflagsV0A = ((TParameter<int>*)digits->GetUserInfo()->FindObject("BGflagsV0A"))->GetVal();
311 }
312 else
313 AliWarning("V0A beam-gas flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
314
315 if (digits->GetUserInfo()->FindObject("BGflagsV0C")) {
316 aBGflagsV0C = ((TParameter<int>*)digits->GetUserInfo()->FindObject("BGflagsV0C"))->GetVal();
317 }
318 else
319 AliWarning("V0C beam-gas flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
320
321 // Now retrieve the channel information: charge smaples + time and
322 // dump it into ADC and Time arrays
c4f89fd4 323 Int_t nEntries = Int_t(digits->GetEntries());
b6fd9c4a 324 Short_t aADC[64][AliVZEROdigit::kNClocks];
325 Float_t aTime[64];
326 Float_t aWidth[64];
327 Bool_t aIntegrator[64];
328 Bool_t aBBflag[64];
329 Bool_t aBGflag[64];
b0d2c2d3 330
c4f89fd4 331 for (Int_t i = 0; i < nEntries; i++) {
332 fVZERO->ResetDigits();
333 digits->GetEvent(i);
334 Int_t ndig = VZEROdigits->GetEntriesFast();
b0d2c2d3 335
c4f89fd4 336 if(ndig == 0) continue;
c4f89fd4 337 for(Int_t k=0; k<ndig; k++){
7c786908 338 AliVZEROdigit* fVZERODigit = (AliVZEROdigit*) VZEROdigits->At(k);
339 // Convert aliroot channel k into FEE channel iChannel before writing data
b6fd9c4a 340 Int_t iChannel = AliVZEROCalibData::GetBoardNumber(fVZERODigit->PMNumber()) * 8 +
341 AliVZEROCalibData::GetFEEChannelNumber(fVZERODigit->PMNumber());
342 for(Int_t iClock = 0; iClock < AliVZEROdigit::kNClocks; ++iClock) aADC[iChannel][iClock] = fVZERODigit->ChargeADC(iClock);
343 aTime[iChannel] = fVZERODigit->Time();
344 aWidth[iChannel] = fVZERODigit->Width();
345 aIntegrator[iChannel]= fVZERODigit->Integrator();
346 if(fVZERODigit->PMNumber() < 32) {
347 aBBflag[iChannel] = (aBBflagsV0C >> fVZERODigit->PMNumber()) & 0x1;
348 aBGflag[iChannel] = (aBGflagsV0C >> fVZERODigit->PMNumber()) & 0x1;
349 }
350 else {
351 aBBflag[iChannel] = (aBBflagsV0A >> (fVZERODigit->PMNumber()-32)) & 0x1;
352 aBGflag[iChannel] = (aBGflagsV0A >> (fVZERODigit->PMNumber()-32)) & 0x1;
353 }
354 AliDebug(1,Form("DDL: %s\tdigit number: %d\tPM number: %d\tADC: %f\tTime: %f",
355 fileName,k,fVZERODigit->PMNumber(),aADC[k],aTime[k]));
c4f89fd4 356 }
c4f89fd4 357 }
b0d2c2d3 358
c4f89fd4 359 // Now fill raw data
360
361 for (Int_t iCIU = 0; iCIU < 8; iCIU++) {
362
363 // decoding of one Channel Interface Unit numbered iCIU - there are 8 channels per CIU (and 8 CIUs) :
364
365 for(Int_t iChannel_Offset = iCIU*8; iChannel_Offset < (iCIU*8)+8; iChannel_Offset=iChannel_Offset+4) {
366 for(Int_t iChannel = iChannel_Offset; iChannel < iChannel_Offset+4; iChannel++) {
b6fd9c4a 367 buffer->WriteChannel(iChannel, aADC[iChannel], aIntegrator[iChannel]);
c4f89fd4 368 }
b6fd9c4a 369 buffer->WriteBeamFlags(&aBBflag[iChannel_Offset],&aBGflag[iChannel_Offset]);
c4f89fd4 370 buffer->WriteMBInfo();
371 buffer->WriteMBFlags();
372 buffer->WriteBeamScalers();
373 }
b6fd9c4a 374
375 for(Int_t iChannel = iCIU*8 + 7; iChannel >= iCIU*8; iChannel--) {
376 buffer->WriteTiming(aTime[iChannel], aWidth[iChannel]);
c4f89fd4 377 }
726d762c 378
c4f89fd4 379 // End of decoding of one CIU card
380
381 } // end of decoding the eight CIUs
382
b0d2c2d3 383 delete buffer;
c4f89fd4 384 fLoader->UnloadDigits();
b0d2c2d3 385}
386
20a489c2 387//_____________________________________________________________________________
388Bool_t AliVZERO::Raw2SDigits(AliRawReader* rawReader){
389 // Converts the VZERO raw data into digits
390 // The method is used for merging simulated and
391 // real data events
392 TStopwatch timer;
393 timer.Start();
394
395 if(!fLoader) {
396 AliError("no VZERO loader found");
397 return kFALSE; }
398
399 TTree* treeD = fLoader->TreeD();
400 if(!treeD) {
401 fLoader->MakeTree("D");
402 treeD = fLoader->TreeD(); }
403
404 AliVZEROdigit digit;
405 AliVZEROdigit* pdigit = &digit;
406 const Int_t kBufferSize = 4000;
407
408 treeD->Branch("VZERO", "AliVZEROdigit", &pdigit, kBufferSize);
409
410 rawReader->Reset();
411 AliVZERORawStream* rawStream = new AliVZERORawStream(rawReader);
412
413 if (!rawStream->Next()) return kFALSE; // No VZERO data found
414
20a489c2 415 fLoader->WriteDigits("OVERWRITE");
416 fLoader->UnloadDigits();
417
418 delete rawStream;
419
420 timer.Stop();
421 timer.Print();
c61a7285 422 return kTRUE;
20a489c2 423}
424
4dbb3fd3 425