]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - VZERO/AliVZERO.cxx
Major fixes to the raw-data simulation. The ADC samples and signal width are added...
[u/mrichter/AliRoot.git] / VZERO / AliVZERO.cxx
index 8d2a6f4081d1daf80cc2e6e375e4822f978e3955..9a076979f1c27047066aeb6c5ba4a96911e150f5 100755 (executable)
@@ -42,6 +42,7 @@
 #include "TBranch.h"
 #include "TClonesArray.h"
 #include "TStopwatch.h"
+#include "TParameter.h"
 
 // --- AliRoot header files ---
 #include "AliRun.h"
 #include "AliRunDigitizer.h"
 #include "AliVZEROdigit.h"
 #include "AliDAQ.h"
+#include "AliRawReader.h"
+#include "AliVZERORawStream.h"
+#include "AliVZEROCalibData.h"
 
 ClassImp(AliVZERO)
+ //__________________________________________________________________
+AliVZERO::AliVZERO(): AliDetector(),
+          fIdSens1(0),
+          fThickness(0.),
+         fThickness1(0.),
+         fMaxStepQua(0.),
+         fMaxStepAlu(0.),
+         fMaxDestepQua(0.),
+         fMaxDestepAlu(0.)
+{
+/// Default Constructor
+    
+    AliDebug(1,Form("default (empty) ctor this=%p",this));
+    fIshunt          = 0;        
+}
 //_____________________________________________________________________________
 AliVZERO::AliVZERO(const char *name, const char *title)
-       : AliDetector(name,title)
+       : AliDetector(name,title),
+         fIdSens1(0),
+         fThickness(4.4),
+        fThickness1(2.0),
+        fMaxStepQua(0.05),
+        fMaxStepAlu(0.01),
+        fMaxDestepQua(-1.0),
+        fMaxDestepAlu(-1.0)
 {
-  //
+  
   // Standard constructor for VZERO Detector
-  //
+  
+  AliDebug(1,Form("ctor this=%p",this));
   
   //  fIshunt       =  1;  // All hits are associated with primary particles  
    
@@ -71,16 +97,16 @@ AliVZERO::AliVZERO(const char *name, const char *title)
    
   gAlice->GetMCApp()->AddHitList(fHits);
 
-  fThickness    =  4.4;   // total thickness of the V0R box in cm
-  fThickness1   =  2.0;   // thickness of scintillating cells in cm
-  
-  fMaxStepQua   =  0.05; 
-  fMaxStepAlu   =  0.01; 
+//   fThickness    =  4.4;   // total thickness of the V0R box in cm
+//   fThickness1   =  2.0;   // thickness of scintillating cells in cm
+//   
+//   fMaxStepQua   =  0.05; 
+//   fMaxStepAlu   =  0.01; 
+//   
+//   fMaxDestepQua =  -1.0;
+//   fMaxDestepAlu =  -1.0;
   
-  fMaxDestepQua =  -1.0;
-  fMaxDestepAlu =  -1.0;
   
-  SetMarkerColor(kRed);
 }
 
 //_____________________________________________________________________________
@@ -101,14 +127,6 @@ AliVZERO::~AliVZERO()
         fDigits=0; }
 }
 
-//_____________________________________________________________________________
-void AliVZERO::BuildGeometry()
-{
-  //
-  // Builds simple ROOT TNode geometry for event display
-  //
-}
 //_____________________________________________________________________________
 void AliVZERO::CreateGeometry()
 {
@@ -124,17 +142,6 @@ void AliVZERO::CreateMaterials()
   //
 }
 
-//_____________________________________________________________________________
-Int_t AliVZERO::DistanceToPrimitive(Int_t /*px*/, Int_t /*py*/)
-{
-  //
-  // Calculates the distance from the mouse to the VZERO on the screen
-  // Dummy routine
-  //
-  
-  return 9999;
-}
 //_____________________________________________________________________________
 void AliVZERO::Init()
 {
@@ -240,64 +247,184 @@ void AliVZERO::Hits2Digits(){
 //_____________________________________________________________________________
 void AliVZERO::Digits2Raw()
 {
-  //
-  // Converts digits of the current event to raw data
-  //
-  AliVZERO *fVZERO = (AliVZERO*)gAlice->GetDetector("VZERO");
-  fLoader->LoadDigits();
-  TTree* digits = fLoader->TreeD();
-  if (!digits) {
-    Error("Digits2Raw", "no digits tree");
-    return;
-  }
-  TClonesArray * VZEROdigits = new TClonesArray("AliVZEROdigit",1000);
-  fVZERO->SetTreeAddress();            
-  digits->GetBranch("VZERODigit")->SetAddress(&VZEROdigits); 
+   //
+   //  Converts digits of the current event to raw data
+   //
   
-  const char *fileName    = AliDAQ::DdlFileName("VZERO",0);
-  AliVZEROBuffer* buffer  = new AliVZEROBuffer(fileName);
+   AliVZERO *fVZERO = (AliVZERO*)gAlice->GetDetector("VZERO");
+   fLoader->LoadDigits();
+   TTree* digits = fLoader->TreeD();
+   if (!digits) {
+      Error("Digits2Raw", "no digits tree");
+      return;
+   }
+   TClonesArray * VZEROdigits = new TClonesArray("AliVZEROdigit",1000);
+   fVZERO->SetTreeAddress();           
+   digits->GetBranch("VZERODigit")->SetAddress(&VZEROdigits); 
   
-  //  Verbose level
-  //  0: Silent
-  //  1: cout messages
-  //  2: txt files with digits 
-  //  BE CAREFUL, verbose level 2 MUST be used only for debugging and
-  //  it is highly suggested to use this mode only for debugging digits files
-  //  reasonably small, because otherwise the size of the txt files can reach
-  //  quickly several MB wasting time and disk space.
+   const char *fileName    = AliDAQ::DdlFileName("VZERO",0);
+   AliVZEROBuffer* buffer  = new AliVZEROBuffer(fileName);
   
-  ofstream ftxt;
-  buffer->SetVerbose(0);
-  Int_t fVerbose = buffer->GetVerbose();
+   // Get Trigger information first
+   // Read trigger inputs from trigger-detector object
+   AliDataLoader * dataLoader = fLoader->GetDigitsDataLoader();
+   if( !dataLoader->IsFileOpen() ) 
+        dataLoader->OpenFile( "READ" );
+   AliTriggerDetector* trgdet = (AliTriggerDetector*)dataLoader->GetDirectory()->Get( "Trigger" );
+   UInt_t triggerInfo = 0;
+   if(trgdet) {
+      triggerInfo = trgdet->GetMask() & 0xffff;
+   }
+   else {
+      AliError(Form("There is no trigger object for %s",fLoader->GetName()));
+   }
 
-  Int_t nEntries = Int_t(digits->GetEntries());
+   buffer->WriteTriggerInfo((UInt_t)triggerInfo); 
+   buffer->WriteTriggerScalers(); 
+   buffer->WriteBunchNumbers(); 
   
-  for (Int_t i = 0; i < nEntries; i++) {
+   Int_t aBBflagsV0A = 0;
+   Int_t aBBflagsV0C = 0;
+   Int_t aBGflagsV0A = 0;
+   Int_t aBGflagsV0C = 0;
+
+   if (digits->GetUserInfo()->FindObject("BBflagsV0A")) {
+     aBBflagsV0A = ((TParameter<int>*)digits->GetUserInfo()->FindObject("BBflagsV0A"))->GetVal();
+   }
+   else
+     AliWarning("V0A beam-beam flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
+
+   if (digits->GetUserInfo()->FindObject("BBflagsV0C")) {
+     aBBflagsV0C = ((TParameter<int>*)digits->GetUserInfo()->FindObject("BBflagsV0C"))->GetVal();
+   }
+   else
+     AliWarning("V0C beam-beam flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
+
+   if (digits->GetUserInfo()->FindObject("BGflagsV0A")) {
+     aBGflagsV0A = ((TParameter<int>*)digits->GetUserInfo()->FindObject("BGflagsV0A"))->GetVal();
+   }
+   else
+     AliWarning("V0A beam-gas flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
+
+   if (digits->GetUserInfo()->FindObject("BGflagsV0C")) {
+     aBGflagsV0C = ((TParameter<int>*)digits->GetUserInfo()->FindObject("BGflagsV0C"))->GetVal();
+   }
+   else
+     AliWarning("V0C beam-gas flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
+
+   // Now retrieve the channel information: charge smaples + time and 
+   // dump it into ADC and Time arrays
+   Int_t nEntries = Int_t(digits->GetEntries());
+   Short_t aADC[64][AliVZEROdigit::kNClocks];
+   Float_t aTime[64];
+   Float_t aWidth[64];
+   Bool_t  aIntegrator[64];
+   Bool_t  aBBflag[64];
+   Bool_t  aBGflag[64];
   
-    fVZERO->ResetDigits();
-    digits->GetEvent(i);
-    Int_t ndig = VZEROdigits->GetEntriesFast(); 
+   for (Int_t i = 0; i < nEntries; i++) {
+     fVZERO->ResetDigits();
+     digits->GetEvent(i);
+     Int_t ndig = VZEROdigits->GetEntriesFast(); 
    
-    if(ndig == 0) continue;
-    if(fVerbose == 2) {ftxt.open("VZEROdigits.txt",ios::app);}
-    for(Int_t k=0; k<ndig; k++){
-        AliVZEROdigit* fVZERODigit = (AliVZEROdigit*) VZEROdigits->At(k);                      
-       Int_t ADC       = fVZERODigit->ADC();
-       Int_t PMNumber  = fVZERODigit->PMNumber();
-       Int_t Time      = fVZERODigit->Time();
-        if(fVerbose == 1) { cout <<"DDL: "<<fileName<< "\tdigit number: "<< k<<"\tPM number: "
-                           <<PMNumber<<"\tADC: "<< ADC << "\tTime: "<< Time << endl;} 
-       if(fVerbose == 2) {
-           ftxt<<"DDL: "<<fileName<< "\tdigit number: "<< k<<"\tPM number: "
-                          <<PMNumber<<"\tADC: "<< ADC << "\tTime: "<< Time << endl;          
-       }
-        buffer->WriteBinary(PMNumber, ADC, Time);
-    }
-  if(fVerbose==2) ftxt.close();
-  }
+     if(ndig == 0) continue;
+     for(Int_t k=0; k<ndig; k++){
+         AliVZEROdigit* fVZERODigit = (AliVZEROdigit*) VZEROdigits->At(k);
+         // Convert aliroot channel k into FEE channel iChannel before writing data
+        Int_t iChannel       = AliVZEROCalibData::GetBoardNumber(fVZERODigit->PMNumber()) * 8 +
+          AliVZEROCalibData::GetFEEChannelNumber(fVZERODigit->PMNumber());
+        for(Int_t iClock = 0; iClock < AliVZEROdigit::kNClocks; ++iClock) aADC[iChannel][iClock] = fVZERODigit->ChargeADC(iClock);
+        aTime[iChannel]      = fVZERODigit->Time();
+        aWidth[iChannel]     = fVZERODigit->Width();
+        aIntegrator[iChannel]= fVZERODigit->Integrator();
+        if(fVZERODigit->PMNumber() < 32) {
+          aBBflag[iChannel] = (aBBflagsV0C >> fVZERODigit->PMNumber()) & 0x1;
+          aBGflag[iChannel] = (aBGflagsV0C >> fVZERODigit->PMNumber()) & 0x1;
+        }
+        else {
+          aBBflag[iChannel] = (aBBflagsV0A >> (fVZERODigit->PMNumber()-32)) & 0x1;
+          aBGflag[iChannel] = (aBGflagsV0A >> (fVZERODigit->PMNumber()-32)) & 0x1;
+        }
+         AliDebug(1,Form("DDL: %s\tdigit number: %d\tPM number: %d\tADC: %f\tTime: %f",
+                        fileName,k,fVZERODigit->PMNumber(),aADC[k],aTime[k])); 
+     }        
+   }
+
+   // Now fill raw data
+          
+   for (Int_t  iCIU = 0; iCIU < 8; iCIU++) { 
+   // decoding of one Channel Interface Unit numbered iCIU - there are 8 channels per CIU (and 8 CIUs) :
+  
+      for(Int_t iChannel_Offset = iCIU*8; iChannel_Offset < (iCIU*8)+8; iChannel_Offset=iChannel_Offset+4) { 
+         for(Int_t iChannel = iChannel_Offset; iChannel < iChannel_Offset+4; iChannel++) {
+             buffer->WriteChannel(iChannel, aADC[iChannel], aIntegrator[iChannel]);       
+         }
+         buffer->WriteBeamFlags(&aBBflag[iChannel_Offset],&aBGflag[iChannel_Offset]); 
+         buffer->WriteMBInfo(); 
+         buffer->WriteMBFlags();   
+         buffer->WriteBeamScalers(); 
+      } 
+
+      for(Int_t iChannel = iCIU*8 + 7; iChannel >= iCIU*8; iChannel--) {
+          buffer->WriteTiming(aTime[iChannel], aWidth[iChannel]); 
+      }
 
+    // End of decoding of one CIU card
+    
+  } // end of decoding the eight CIUs
+     
   delete buffer;
-  fLoader->UnloadDigits();
+  fLoader->UnloadDigits();  
+}
+
+//_____________________________________________________________________________
+Bool_t AliVZERO::Raw2SDigits(AliRawReader* rawReader){
+  // Converts the VZERO raw data into digits
+  // The method is used for merging simulated and
+  // real data events
+  TStopwatch timer;
+  timer.Start();
+
+  if(!fLoader) {
+    AliError("no VZERO loader found");
+    return kFALSE; }
+
+  TTree* treeD  = fLoader->TreeD();
+  if(!treeD) {
+      fLoader->MakeTree("D");
+      treeD = fLoader->TreeD(); }
+        
+  AliVZEROdigit  digit;
+  AliVZEROdigit* pdigit = &digit;
+  const Int_t kBufferSize = 4000;
+   
+  treeD->Branch("VZERO", "AliVZEROdigit",  &pdigit, kBufferSize);
+
+  rawReader->Reset();
+  AliVZERORawStream* rawStream  = new AliVZERORawStream(rawReader);    
+     
+  if (!rawStream->Next()) return kFALSE; // No VZERO data found
+  
+  for(Int_t i=0; i<64; i++) {
+      new(pdigit) AliVZEROdigit(i, rawStream->GetADC(i), rawStream->GetTime(i)); 
+      treeD->Fill();
+  }
+// Checks if everything is OK by printing results 
+
+//   for(int i=0;i<64;i++) {
+//     printf("Channel %d : %f %f \n",i,rawStream->GetADC(i),rawStream->GetTime(i)); }
+//   treeD->Print(); printf(" \n"); 
+       
+  fLoader->WriteDigits("OVERWRITE");
+  fLoader->UnloadDigits();     
+       
+  delete rawStream;
+
+  timer.Stop();
+  timer.Print();
+  return kTRUE;
 }