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::BuildGeometry()
132 // Builds simple ROOT TNode geometry for event display
136 //_____________________________________________________________________________
137 void AliVZERO::CreateGeometry()
140 // Builds simple Geant3 geometry
143 //_____________________________________________________________________________
144 void AliVZERO::CreateMaterials()
147 // Creates materials used for Geant3 geometry
151 //_____________________________________________________________________________
152 Int_t AliVZERO::DistanceToPrimitive(Int_t /*px*/, Int_t /*py*/)
155 // Calculates the distance from the mouse to the VZERO on the screen
162 //_____________________________________________________________________________
163 void AliVZERO::Init()
166 // Initialises the VZERO class after it has been built
171 //_____________________________________________________________________________
172 void AliVZERO::SetMaxStepQua(Float_t p1)
175 // Possible parametrisation of steps in active materials
180 //_____________________________________________________________________________
181 void AliVZERO::SetMaxStepAlu(Float_t p1)
184 // Possible parametrisation of steps in Aluminum foils (not used in
190 //_____________________________________________________________________________
191 void AliVZERO::SetMaxDestepQua(Float_t p1)
194 // Possible parametrisation of steps in active materials (quartz)
199 //_____________________________________________________________________________
200 void AliVZERO::SetMaxDestepAlu(Float_t p1)
203 // Possible parametrisation of steps in Aluminum (not used in
209 //_____________________________________________________________________________
210 AliLoader* AliVZERO::MakeLoader(const char* topfoldername)
213 // Builds VZEROgetter (AliLoader type)
214 // if detector wants to use customized getter, it must overload this method
216 // Info("MakeLoader","Creating AliVZEROLoader. Top folder is %s.",topfoldername);
218 AliDebug(1,Form("Creating AliVZEROLoader, Top folder is %s ",topfoldername));
219 fLoader = new AliVZEROLoader(GetName(),topfoldername);
223 //_____________________________________________________________________________
224 void AliVZERO::SetTreeAddress()
227 // Sets tree address for hits.
229 if (fLoader->TreeH() && (fHits == 0x0))
230 fHits = new TClonesArray("AliVZEROhit", 400);
232 AliDetector::SetTreeAddress();
235 //_____________________________________________________________________________
236 AliDigitizer* AliVZERO::CreateDigitizer(AliRunDigitizer* manager) const
239 // Creates a digitizer for VZERO
241 return new AliVZERODigitizer(manager);
244 //_____________________________________________________________________________
245 void AliVZERO::Hits2Digits(){
247 // Converts hits to digits of the current event
250 const char *alifile = "galice.root";
252 // Create the run digitizer
253 AliRunDigitizer* manager = new AliRunDigitizer(1, 1);
254 manager->SetInputStream(0, alifile);
255 manager->SetOutputFile("H2Dfile");
257 // Creates the VZERO digitizer
258 AliVZERODigitizer* dig = new AliVZERODigitizer(manager);
260 // Creates the digits
264 //_____________________________________________________________________________
265 void AliVZERO::Digits2Raw()
268 // Converts digits of the current event to raw data
271 AliVZERO *fVZERO = (AliVZERO*)gAlice->GetDetector("VZERO");
272 fLoader->LoadDigits();
273 TTree* digits = fLoader->TreeD();
275 Error("Digits2Raw", "no digits tree");
278 TClonesArray * VZEROdigits = new TClonesArray("AliVZEROdigit",1000);
279 fVZERO->SetTreeAddress();
280 digits->GetBranch("VZERODigit")->SetAddress(&VZEROdigits);
282 const char *fileName = AliDAQ::DdlFileName("VZERO",0);
283 AliVZEROBuffer* buffer = new AliVZEROBuffer(fileName);
288 // 2: txt files with digits
289 // BE CAREFUL, verbose level 2 MUST be used only for debugging and
290 // it is highly suggested to use this mode only for debugging digits files
291 // reasonably small, because otherwise the size of the txt files can reach
292 // quickly several MB wasting time and disk space.
295 buffer->SetVerbose(0);
296 Int_t verbose = buffer->GetVerbose();
298 // Get Trigger information first
299 // Read trigger inputs from trigger-detector object
300 AliDataLoader * dataLoader = fLoader->GetDigitsDataLoader();
301 if( !dataLoader->IsFileOpen() )
302 dataLoader->OpenFile( "READ" );
303 AliTriggerDetector* trgdet = (AliTriggerDetector*)dataLoader->GetDirectory()->Get( "Trigger" );
304 UInt_t triggerInfo = 0;
306 triggerInfo = trgdet->GetMask() & 0xffff;
309 AliError(Form("There is no trigger object for %s",fLoader->GetName()));
312 buffer->WriteTriggerInfo((UInt_t)triggerInfo);
313 buffer->WriteTriggerScalers();
314 buffer->WriteBunchNumbers();
316 // Now retrieve the channel information: charge+time and
317 // dump it into ADC and Time arrays
318 // We assume here an ordered (by PMNumber) array of
321 Int_t nEntries = Int_t(digits->GetEntries());
326 for (Int_t i = 0; i < nEntries; i++) {
327 fVZERO->ResetDigits();
329 Int_t ndig = VZEROdigits->GetEntriesFast();
331 if(ndig == 0) continue;
332 if(verbose == 2) {ftxt.open("VZEROdigits.txt",ios::app);}
333 for(Int_t k=0; k<ndig; k++){
334 AliVZEROdigit* fVZERODigit = (AliVZEROdigit*) VZEROdigits->At(k);
335 // Convert aliroot channel k into FEE channel iChannel before writing data
336 Int_t iChannel = buffer->GetOnlineChannel(k);
337 ADC[iChannel] = (UInt_t) fVZERODigit->ADC();
338 PMNumber[iChannel] = fVZERODigit->PMNumber();
339 Time[iChannel] = (UInt_t) fVZERODigit->Time();
340 if(verbose == 1) { cout <<"DDL: "<<fileName<< "\tdigit number: "<< k<<"\tPM number: "
341 <<PMNumber[k]<<"\tADC: "<< ADC[k] << "\tTime: "<< Time[k] << endl;}
343 ftxt<<"DDL: "<<fileName<< "\tdigit number: "<< k<<"\tPM number: "
344 <<PMNumber[k]<<"\tADC: "<< ADC[k] << "\tTime: "<< Time[k] << endl;}
345 // printf("DDL: %s, channel: %d, PM: %d, ADC: %d, Time: %d \n",
346 // fileName,k,PMNumber[k],ADC[k],Time[k]);
348 if(verbose==2) ftxt.close();
353 for (Int_t iCIU = 0; iCIU < 8; iCIU++) {
355 // decoding of one Channel Interface Unit numbered iCIU - there are 8 channels per CIU (and 8 CIUs) :
357 for(Int_t iChannel_Offset = iCIU*8; iChannel_Offset < (iCIU*8)+8; iChannel_Offset=iChannel_Offset+4) {
358 for(Int_t iChannel = iChannel_Offset; iChannel < iChannel_Offset+4; iChannel++) {
359 buffer->WriteChannel(iChannel, ADC[iChannel], Time[iChannel]);
361 buffer->WriteBeamFlags();
362 buffer->WriteMBInfo();
363 buffer->WriteMBFlags();
364 buffer->WriteBeamScalers();
366 for(Int_t iChannel=0; iChannel < 8; iChannel++) {
367 buffer->WriteTiming(iChannel, ADC[iChannel], Time[iChannel]);
370 // End of decoding of one CIU card
372 } // end of decoding the eight CIUs
375 fLoader->UnloadDigits();
378 //_____________________________________________________________________________
379 Bool_t AliVZERO::Raw2SDigits(AliRawReader* rawReader){
380 // Converts the VZERO raw data into digits
381 // The method is used for merging simulated and
387 AliError("no VZERO loader found");
390 TTree* treeD = fLoader->TreeD();
392 fLoader->MakeTree("D");
393 treeD = fLoader->TreeD(); }
396 AliVZEROdigit* pdigit = &digit;
397 const Int_t kBufferSize = 4000;
399 treeD->Branch("VZERO", "AliVZEROdigit", &pdigit, kBufferSize);
402 AliVZERORawStream* rawStream = new AliVZERORawStream(rawReader);
404 if (!rawStream->Next()) return kFALSE; // No VZERO data found
406 for(Int_t i=0; i<64; i++) {
407 new(pdigit) AliVZEROdigit(i, (Int_t)rawStream->GetADC(i), (Int_t)rawStream->GetTime(i));
411 // Checks if everything is OK by printing results
413 // for(int i=0;i<64;i++) {
414 // printf("Channel %d : %d %d \n",i,rawStream->GetADC(i),rawStream->GetTime(i)); }
415 // treeD->Print(); printf(" \n");
417 fLoader->WriteDigits("OVERWRITE");
418 fLoader->UnloadDigits();