]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - VZERO/AliVZERO.cxx
Added graphical reference to help DQM shifter. Updated sim TOF QA histograms. (F...
[u/mrichter/AliRoot.git] / VZERO / AliVZERO.cxx
index a1cee7fc632a3a97b71f773b92748763d4dca70c..947d88fa82d214f2f96514bde79d483620706da7 100755 (executable)
@@ -53,6 +53,8 @@
 #include "AliRunDigitizer.h"
 #include "AliVZEROdigit.h"
 #include "AliDAQ.h"
+#include "AliRawReader.h"
+#include "AliVZERORawStream.h"
 
 ClassImp(AliVZERO)
  //__________________________________________________________________
@@ -123,14 +125,6 @@ AliVZERO::~AliVZERO()
         fDigits=0; }
 }
 
-//_____________________________________________________________________________
-void AliVZERO::BuildGeometry()
-{
-  //
-  // Builds simple ROOT TNode geometry for event display
-  //
-}
 //_____________________________________________________________________________
 void AliVZERO::CreateGeometry()
 {
@@ -146,17 +140,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()
 {
@@ -262,64 +245,167 @@ 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
+   //
+  
+   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); 
+  
+   const char *fileName    = AliDAQ::DdlFileName("VZERO",0);
+   AliVZEROBuffer* buffer  = new AliVZEROBuffer(fileName);
   
-  const char *fileName    = AliDAQ::DdlFileName("VZERO",0);
-  AliVZEROBuffer* buffer  = new AliVZEROBuffer(fileName);
+   //  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.
   
-  //  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.
+   ofstream ftxt;
+   buffer->SetVerbose(0);
+   Int_t verbose = 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()));
+   }
+
+   buffer->WriteTriggerInfo((UInt_t)triggerInfo); 
+   buffer->WriteTriggerScalers(); 
+   buffer->WriteBunchNumbers(); 
   
-  ofstream ftxt;
-  buffer->SetVerbose(0);
-  Int_t fVerbose = buffer->GetVerbose();
+   // Now retrieve the channel information: charge+time and 
+   // dump it into ADC and Time arrays
+   // We assume here an ordered (by PMNumber) array of
+   // digits!!
 
-  Int_t nEntries = Int_t(digits->GetEntries());
+   Int_t nEntries = Int_t(digits->GetEntries());
+   Float_t ADC[64];
+   Int_t PMNumber[64];
+   Float_t Time[64];
+   Bool_t Integrator[64];
   
-  for (Int_t i = 0; i < nEntries; i++) {
+   for (Int_t i = 0; i < nEntries; i++) {
+     fVZERO->ResetDigits();
+     digits->GetEvent(i);
+     Int_t ndig = VZEROdigits->GetEntriesFast(); 
+   
+     if(ndig == 0) continue;
+     if(verbose == 2) {ftxt.open("VZEROdigits.txt",ios::app);}
+     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      = buffer->GetOnlineChannel(k);             
+        ADC[iChannel]       = fVZERODigit->ADC();
+        PMNumber[iChannel]  = fVZERODigit->PMNumber();
+        Time[iChannel]      = fVZERODigit->Time();
+        Integrator[iChannel]= fVZERODigit->Integrator(); 
+         if(verbose == 1) { cout <<"DDL: "<<fileName<< "\tdigit number: "<< k<<"\tPM number: "
+                           <<PMNumber[k]<<"\tADC: "<< ADC[k] << "\tTime: "<< Time[k] << endl;} 
+        if(verbose == 2) {
+             ftxt<<"DDL: "<<fileName<< "\tdigit number: "<< k<<"\tPM number: "
+                          <<PMNumber[k]<<"\tADC: "<< ADC[k] << "\tTime: "<< Time[k] << endl;}        
+//      printf("DDL: %s, channel: %d, PM: %d, ADC: %f, Time: %f \n", 
+//                 fileName,k,PMNumber[k],ADC[k],Time[k]); 
+     }        
+   if(verbose==2) ftxt.close();
+   }
+
+   // 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) :
   
-    fVZERO->ResetDigits();
-    digits->GetEvent(i);
-    Int_t ndig = VZEROdigits->GetEntriesFast(); 
+      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, (Int_t) ADC[iChannel], Time[iChannel], Integrator[iChannel]);       
+         }
+         buffer->WriteBeamFlags(); 
+         buffer->WriteMBInfo(); 
+         buffer->WriteMBFlags();   
+         buffer->WriteBeamScalers(); 
+      } 
+//      for(Int_t iChannel=0; iChannel < 8; iChannel++) {
+      for(Int_t iChannel=7; iChannel >= 0; iChannel--) {
+          buffer->WriteTiming(iChannel, (Int_t) ADC[iChannel], Time[iChannel]); 
+      }
+
+    // End of decoding of one CIU card
+    
+  } // end of decoding the eight CIUs
+     
+  delete buffer;
+  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;
    
-    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();
+  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 
 
-  delete buffer;
-  fLoader->UnloadDigits();
+//   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;
 }