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"
46 // --- AliRoot header files ---
50 #include "AliVZEROLoader.h"
51 #include "AliVZERODigitizer.h"
52 #include "AliVZEROBuffer.h"
53 #include "AliRunDigitizer.h"
54 #include "AliVZEROdigit.h"
56 #include "AliRawReader.h"
57 #include "AliVZERORawStream.h"
60 //__________________________________________________________________
61 AliVZERO::AliVZERO(): AliDetector(),
70 /// Default Constructor
72 AliDebug(1,Form("default (empty) ctor this=%p",this));
75 //_____________________________________________________________________________
76 AliVZERO::AliVZERO(const char *name, const char *title)
77 : AliDetector(name,title),
87 // Standard constructor for VZERO Detector
89 AliDebug(1,Form("ctor this=%p",this));
91 // fIshunt = 1; // All hits are associated with primary particles
93 fHits = new TClonesArray("AliVZEROhit", 400);
94 fDigits = new TClonesArray("AliVZEROdigit",400);
96 gAlice->GetMCApp()->AddHitList(fHits);
98 // fThickness = 4.4; // total thickness of the V0R box in cm
99 // fThickness1 = 2.0; // thickness of scintillating cells in cm
101 // fMaxStepQua = 0.05;
102 // fMaxStepAlu = 0.01;
104 // fMaxDestepQua = -1.0;
105 // fMaxDestepAlu = -1.0;
110 //_____________________________________________________________________________
111 AliVZERO::~AliVZERO()
114 // Default destructor for VZERO Detector
128 //_____________________________________________________________________________
129 void AliVZERO::CreateGeometry()
132 // Builds simple Geant3 geometry
135 //_____________________________________________________________________________
136 void AliVZERO::CreateMaterials()
139 // Creates materials used for Geant3 geometry
143 //_____________________________________________________________________________
144 void AliVZERO::Init()
147 // Initialises the VZERO class after it has been built
152 //_____________________________________________________________________________
153 void AliVZERO::SetMaxStepQua(Float_t p1)
156 // Possible parametrisation of steps in active materials
161 //_____________________________________________________________________________
162 void AliVZERO::SetMaxStepAlu(Float_t p1)
165 // Possible parametrisation of steps in Aluminum foils (not used in
171 //_____________________________________________________________________________
172 void AliVZERO::SetMaxDestepQua(Float_t p1)
175 // Possible parametrisation of steps in active materials (quartz)
180 //_____________________________________________________________________________
181 void AliVZERO::SetMaxDestepAlu(Float_t p1)
184 // Possible parametrisation of steps in Aluminum (not used in
190 //_____________________________________________________________________________
191 AliLoader* AliVZERO::MakeLoader(const char* topfoldername)
194 // Builds VZEROgetter (AliLoader type)
195 // if detector wants to use customized getter, it must overload this method
197 // Info("MakeLoader","Creating AliVZEROLoader. Top folder is %s.",topfoldername);
199 AliDebug(1,Form("Creating AliVZEROLoader, Top folder is %s ",topfoldername));
200 fLoader = new AliVZEROLoader(GetName(),topfoldername);
204 //_____________________________________________________________________________
205 void AliVZERO::SetTreeAddress()
208 // Sets tree address for hits.
210 if (fLoader->TreeH() && (fHits == 0x0))
211 fHits = new TClonesArray("AliVZEROhit", 400);
213 AliDetector::SetTreeAddress();
216 //_____________________________________________________________________________
217 AliDigitizer* AliVZERO::CreateDigitizer(AliRunDigitizer* manager) const
220 // Creates a digitizer for VZERO
222 return new AliVZERODigitizer(manager);
225 //_____________________________________________________________________________
226 void AliVZERO::Hits2Digits(){
228 // Converts hits to digits of the current event
231 const char *alifile = "galice.root";
233 // Create the run digitizer
234 AliRunDigitizer* manager = new AliRunDigitizer(1, 1);
235 manager->SetInputStream(0, alifile);
236 manager->SetOutputFile("H2Dfile");
238 // Creates the VZERO digitizer
239 AliVZERODigitizer* dig = new AliVZERODigitizer(manager);
241 // Creates the digits
245 //_____________________________________________________________________________
246 void AliVZERO::Digits2Raw()
249 // Converts digits of the current event to raw data
252 AliVZERO *fVZERO = (AliVZERO*)gAlice->GetDetector("VZERO");
253 fLoader->LoadDigits();
254 TTree* digits = fLoader->TreeD();
256 Error("Digits2Raw", "no digits tree");
259 TClonesArray * VZEROdigits = new TClonesArray("AliVZEROdigit",1000);
260 fVZERO->SetTreeAddress();
261 digits->GetBranch("VZERODigit")->SetAddress(&VZEROdigits);
263 const char *fileName = AliDAQ::DdlFileName("VZERO",0);
264 AliVZEROBuffer* buffer = new AliVZEROBuffer(fileName);
269 // 2: txt files with digits
270 // BE CAREFUL, verbose level 2 MUST be used only for debugging and
271 // it is highly suggested to use this mode only for debugging digits files
272 // reasonably small, because otherwise the size of the txt files can reach
273 // quickly several MB wasting time and disk space.
276 buffer->SetVerbose(0);
277 Int_t verbose = buffer->GetVerbose();
279 // Get Trigger information first
280 // Read trigger inputs from trigger-detector object
281 AliDataLoader * dataLoader = fLoader->GetDigitsDataLoader();
282 if( !dataLoader->IsFileOpen() )
283 dataLoader->OpenFile( "READ" );
284 AliTriggerDetector* trgdet = (AliTriggerDetector*)dataLoader->GetDirectory()->Get( "Trigger" );
285 UInt_t triggerInfo = 0;
287 triggerInfo = trgdet->GetMask() & 0xffff;
290 AliError(Form("There is no trigger object for %s",fLoader->GetName()));
293 buffer->WriteTriggerInfo((UInt_t)triggerInfo);
294 buffer->WriteTriggerScalers();
295 buffer->WriteBunchNumbers();
297 // Now retrieve the channel information: charge+time and
298 // dump it into ADC and Time arrays
299 // We assume here an ordered (by PMNumber) array of
302 Int_t nEntries = Int_t(digits->GetEntries());
306 Bool_t Integrator[64];
308 for (Int_t i = 0; i < nEntries; i++) {
309 fVZERO->ResetDigits();
311 Int_t ndig = VZEROdigits->GetEntriesFast();
313 if(ndig == 0) continue;
314 if(verbose == 2) {ftxt.open("VZEROdigits.txt",ios::app);}
315 for(Int_t k=0; k<ndig; k++){
316 AliVZEROdigit* fVZERODigit = (AliVZEROdigit*) VZEROdigits->At(k);
317 // Convert aliroot channel k into FEE channel iChannel before writing data
318 Int_t iChannel = buffer->GetOnlineChannel(k);
319 ADC[iChannel] = fVZERODigit->ADC();
320 PMNumber[iChannel] = fVZERODigit->PMNumber();
321 Time[iChannel] = fVZERODigit->Time();
322 Integrator[iChannel]= fVZERODigit->Integrator();
323 if(verbose == 1) { cout <<"DDL: "<<fileName<< "\tdigit number: "<< k<<"\tPM number: "
324 <<PMNumber[k]<<"\tADC: "<< ADC[k] << "\tTime: "<< Time[k] << endl;}
326 ftxt<<"DDL: "<<fileName<< "\tdigit number: "<< k<<"\tPM number: "
327 <<PMNumber[k]<<"\tADC: "<< ADC[k] << "\tTime: "<< Time[k] << endl;}
328 // printf("DDL: %s, channel: %d, PM: %d, ADC: %f, Time: %f \n",
329 // fileName,k,PMNumber[k],ADC[k],Time[k]);
331 if(verbose==2) ftxt.close();
336 for (Int_t iCIU = 0; iCIU < 8; iCIU++) {
338 // decoding of one Channel Interface Unit numbered iCIU - there are 8 channels per CIU (and 8 CIUs) :
340 for(Int_t iChannel_Offset = iCIU*8; iChannel_Offset < (iCIU*8)+8; iChannel_Offset=iChannel_Offset+4) {
341 for(Int_t iChannel = iChannel_Offset; iChannel < iChannel_Offset+4; iChannel++) {
342 buffer->WriteChannel(iChannel, (Int_t) ADC[iChannel], Time[iChannel], Integrator[iChannel]);
344 buffer->WriteBeamFlags();
345 buffer->WriteMBInfo();
346 buffer->WriteMBFlags();
347 buffer->WriteBeamScalers();
349 // for(Int_t iChannel=0; iChannel < 8; iChannel++) {
350 for(Int_t iChannel=7; iChannel >= 0; iChannel--) {
351 buffer->WriteTiming(iChannel, (Int_t) ADC[iChannel], Time[iChannel]);
354 // End of decoding of one CIU card
356 } // end of decoding the eight CIUs
359 fLoader->UnloadDigits();
362 //_____________________________________________________________________________
363 Bool_t AliVZERO::Raw2SDigits(AliRawReader* rawReader){
364 // Converts the VZERO raw data into digits
365 // The method is used for merging simulated and
371 AliError("no VZERO loader found");
374 TTree* treeD = fLoader->TreeD();
376 fLoader->MakeTree("D");
377 treeD = fLoader->TreeD(); }
380 AliVZEROdigit* pdigit = &digit;
381 const Int_t kBufferSize = 4000;
383 treeD->Branch("VZERO", "AliVZEROdigit", &pdigit, kBufferSize);
386 AliVZERORawStream* rawStream = new AliVZERORawStream(rawReader);
388 if (!rawStream->Next()) return kFALSE; // No VZERO data found
390 for(Int_t i=0; i<64; i++) {
391 new(pdigit) AliVZEROdigit(i, rawStream->GetADC(i), rawStream->GetTime(i));
395 // Checks if everything is OK by printing results
397 // for(int i=0;i<64;i++) {
398 // printf("Channel %d : %f %f \n",i,rawStream->GetADC(i),rawStream->GetTime(i)); }
399 // treeD->Print(); printf(" \n");
401 fLoader->WriteDigits("OVERWRITE");
402 fLoader->UnloadDigits();