]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - AD/AliADReconstructor.cxx
Merge branch 'TPCdev' of https://git.cern.ch/reps/AliRoot into TPCdev
[u/mrichter/AliRoot.git] / AD / AliADReconstructor.cxx
index 1ceac8337cfe3d9123aff6d3dcb2e9afa05fc2a2..c102723dd0cb6ee4057bb24b1018ee7f8d7df379 100644 (file)
 //                                                                          //
 //  Class for AD reconstruction                                         //
 //////////////////////////////////////////////////////////////////////////////
+#include <TParameter.h>
 
 #include "AliRawReader.h"
+#include "AliGRPObject.h"
+#include "AliCDBManager.h"
+#include "AliCDBStorage.h"
+#include "AliCDBEntry.h"
+#include "AliESDEvent.h"
 
 #include "AliADReconstructor.h"
-#include "AliESDEvent.h"
 #include "AliADdigit.h"
 #include "AliESDAD.h"
+#include "AliADConst.h"
+#include "AliADCalibData.h"
+#include "AliADRawStream.h"
 
 ClassImp(AliADReconstructor)
-
+//_____________________________________________________________________________
 AliADReconstructor:: AliADReconstructor():
   AliReconstructor(),
   fESDAD(0x0),
+  fCalibData(NULL),
   fDigitsArray(0)
+
 {
+  fCalibData = GetCalibData();
   // Default constructor  
   // Get calibration data
 
@@ -63,12 +74,71 @@ void AliADReconstructor::Init()
     fESDAD  = new AliESDAD;
 }
 
-void AliADReconstructor::ConvertDigits(AliRawReader* /*rawReader*/, TTree* /*digitsTree*/) const
+//_____________________________________________________________________________
+void AliADReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
 {
+// converts RAW to digits 
+
+  if (!digitsTree) {
+    AliError("No digits tree!");
+    return;
+  }
+
+  if (!fDigitsArray){
+    fDigitsArray = new TClonesArray("AliADdigit", 16);
+    digitsTree->Branch("ADDigit", &fDigitsArray);
+    }
+
+  rawReader->Reset();
+  AliADRawStream rawStream(rawReader);
+  if (rawStream.Next()) { 
+
+    Int_t aBBflagsADA = 0;
+    Int_t aBBflagsADC = 0;
+    Int_t aBGflagsADA = 0;
+    Int_t aBGflagsADC = 0;
+
+    for(Int_t iChannel=0; iChannel < 16; ++iChannel) {
+      Int_t offlineCh = rawStream.GetOfflineChannel(iChannel);
+      // ADC charge samples
+      Short_t chargeADC[kNClocks];
+      for(Int_t iClock=0; iClock < kNClocks; ++iClock) {
+       chargeADC[iClock] = rawStream.GetPedestal(iChannel,iClock);
+      }
+      // Integrator flag
+      Bool_t integrator = rawStream.GetIntegratorFlag(iChannel,kNClocks/2);
+      // Beam-beam and beam-gas flags
+      if(offlineCh<8) {
+       if (rawStream.GetBBFlag(iChannel,kNClocks/2)) aBBflagsADC |= (1 << offlineCh);
+       if (rawStream.GetBGFlag(iChannel,kNClocks/2)) aBGflagsADC |= (1 << offlineCh);
+      } else {
+       if (rawStream.GetBBFlag(iChannel,kNClocks/2)) aBBflagsADA |= (1 << (offlineCh-32));
+       if (rawStream.GetBGFlag(iChannel,kNClocks/2)) aBGflagsADA |= (1 << (offlineCh-32));
+      }
+      // HPTDC data (leading time and width)
+      Int_t board = AliADCalibData::GetBoardNumber(offlineCh);
+      Float_t time = rawStream.GetTime(iChannel)*fCalibData->GetTimeResolution(board);
+      Float_t width = rawStream.GetWidth(iChannel)*fCalibData->GetWidthResolution(board);
+      // Add a digit
+      if(!fCalibData->IsChannelDead(iChannel)){
+         new ((*fDigitsArray)[fDigitsArray->GetEntriesFast()]) AliADdigit(offlineCh, time, width,integrator, chargeADC);
+      }
+    }
+    // Store the BB and BG flags in the digits tree (user info)
+    digitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsADA",aBBflagsADA));
+    digitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsADC",aBBflagsADC));
+    digitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsADA",aBGflagsADA));
+    digitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsADC",aBGflagsADC));
+
+
+    digitsTree->Fill();
+  }
+
+  fDigitsArray->Clear();
 
-  printf("Converting digits for AD .. not implemented \n");
 }
 
+//_____________________________________________________________________________
 void AliADReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,AliESDEvent* esd) const
 {
 
@@ -117,4 +187,30 @@ void AliADReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,AliE
   fDigitsArray->Clear();
 }
 
+//_____________________________________________________________________________
+AliADCalibData* AliADReconstructor::GetCalibData() const
+{
+  AliCDBManager *man = AliCDBManager::Instance();
+
+  AliCDBEntry *entry=0;
+
+  //entry = man->Get("AD/Calib/Data");
+  //if(!entry){
+    //AliWarning("Load of calibration data from default storage failed!");
+    //AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
+       
+    man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+    man->SetRun(1);
+    entry = man->Get("AD/Calib/Data");
+  //}
+  // Retrieval of data in directory AD/Calib/Data:
+
+  AliADCalibData *calibdata = 0;
+
+  if (entry) calibdata = (AliADCalibData*) entry->GetObject();
+  if (!calibdata)  AliFatal("No calibration data from calibration database !");
+
+  return calibdata;
+}
+