Macro to calculate the needed HV values as a function of the required MIP signal.
[u/mrichter/AliRoot.git] / VZERO / AliVZEROTriggerSimulator.cxx
index 878727f..78c377c 100644 (file)
@@ -22,6 +22,7 @@
 \r
 #include <TTree.h>\r
 #include <TClonesArray.h>\r
+#include <TParameter.h>\r
 \r
 #include "AliLog.h"\r
 #include "AliCDBManager.h"\r
@@ -32,6 +33,9 @@
 #include "AliVZEROLogicalSignal.h"\r
 #include "AliVZEROTriggerSimulator.h"\r
 #include "AliVZEROdigit.h"\r
+#include "AliVZEROCalibData.h"\r
+#include "AliVZEROConst.h"\r
+#include "AliCTPTimeParams.h"\r
 \r
 ClassImp(AliVZEROTriggerSimulator)\r
 \r
@@ -41,6 +45,7 @@ TObject(),fTriggerData(NULL),fDigitsTree(digitsTree),fDigits(digits),fTriggerWor
 {\r
        // constructor\r
        fTriggerData = LoadTriggerData();\r
+       LoadClockOffset();\r
        \r
        for(int i=0;i<64;i++) {\r
                fBBFlags[i] = fBGFlags[i] = kFALSE;\r
@@ -61,6 +66,7 @@ TObject(),fTriggerData(NULL),fDigitsTree(NULL),fDigits(NULL),fTriggerWord(0)
 {\r
        // Default constructor\r
        fTriggerData = LoadTriggerData();\r
+       LoadClockOffset();\r
 \r
        for(int i=0;i<64;i++) {\r
                fBBFlags[i] = fBGFlags[i] = kFALSE;\r
@@ -79,12 +85,14 @@ TObject(),fTriggerData(NULL),fDigitsTree(NULL),fDigits(NULL),fTriggerWord(0)
 //_____________________________________________________________________________\r
 AliVZEROTriggerSimulator::~AliVZEROTriggerSimulator(){\r
 // Destructor\r
-       if(fBBGate) delete [] fBBGate;\r
-       if(fBGGate) delete [] fBGGate;\r
-       if(fBBLatch) delete [] fBBLatch;\r
-       if(fBBReset) delete [] fBBReset;\r
-       if(fBGLatch) delete [] fBGLatch;\r
-       if(fBGReset) delete [] fBGReset;\r
+  for (Int_t i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
+    delete fBBGate[i];\r
+    delete fBGGate[i];\r
+    delete fBBLatch[i];\r
+    delete fBBReset[i];\r
+    delete fBGLatch[i];\r
+    delete fBGReset[i];\r
+  }\r
 }\r
 \r
 //_____________________________________________________________________________\r
@@ -120,11 +128,8 @@ AliVZEROTriggerData * AliVZEROTriggerSimulator::LoadTriggerData() const
        \r
        entry = man->Get("VZERO/Trigger/Data");\r
        if(!entry){\r
-               AliWarning("Load of calibration data from default storage failed!");\r
-               AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");\r
-               \r
-               man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");\r
-               entry = man->Get("VZERO/Trigger/Data",0);\r
+               AliFatal("Load of trigger calibration data from default storage failed!");\r
+               return NULL;\r
        }\r
        \r
        // Retrieval of data in directory VZERO/Calib/Trigger:\r
@@ -137,6 +142,46 @@ AliVZEROTriggerData * AliVZEROTriggerSimulator::LoadTriggerData() const
        return triggerData;\r
 }\r
 \r
+\r
+//_____________________________________________________________________________\r
+void AliVZEROTriggerSimulator::LoadClockOffset()\r
+{\r
+  // This method is used in order to\r
+  // retrieve the TDC clock offset including\r
+  // roll-over, trig count and CTP L0->L1 delay\r
+\r
+  AliCDBEntry *entry0 = AliCDBManager::Instance()->Get("VZERO/Calib/Data");\r
+  if (!entry0) {\r
+    AliFatal("V0 Calib object is not found in OCDB !");\r
+    return;\r
+  }\r
+  AliVZEROCalibData *calibdata = (AliVZEROCalibData*) entry0->GetObject();\r
+\r
+  AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");\r
+  if (!entry) {\r
+    AliFatal("CTP timing parameters are not found in OCDB !");\r
+    return;\r
+  }\r
+  AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();\r
+  Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;\r
+\r
+  AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");\r
+  if (!entry1) {\r
+    AliFatal("CTP time-alignment is not found in OCDB !");\r
+    return;\r
+  }\r
+  AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();\r
+  l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);\r
+\r
+  for(Int_t board = 0; board < AliVZEROTriggerData::kNCIUBoards; ++board) {\r
+    fClockOffset[board] = (((Float_t)calibdata->GetRollOver(board)-\r
+                           (Float_t)calibdata->GetTriggerCountOffset(board))*25.0-\r
+                          l1Delay+\r
+                          kV0Offset);\r
+    AliDebug(1,Form("Board %d Offset %f",board,fClockOffset[board]));\r
+  }\r
+}\r
+\r
 //_____________________________________________________________________________\r
 void AliVZEROTriggerSimulator::Run() {\r
        //AliInfo("Generating VZERO Triggers");\r
@@ -153,11 +198,12 @@ void AliVZEROTriggerSimulator::Run() {
                        \r
                        Int_t integrator = digit->Integrator();\r
                        Int_t pmNumber   = digit->PMNumber();\r
-                       Int_t board   = pmNumber / 8;\r
-                       Int_t channel = pmNumber % 8;\r
+                       Int_t board   = AliVZEROCalibData::GetBoardNumber(pmNumber);\r
+                       Int_t channel = AliVZEROCalibData::GetFEEChannelNumber(pmNumber);\r
+                       if (board < 0 || channel < 0) continue;\r
                        \r
                        if(fTriggerData->GetEnableCharge(board,channel)) {\r
-                               fCharges[pmNumber] = digit->ADC();\r
+                               fCharges[pmNumber] = digit->ChargeADC(AliVZEROdigit::kNClocks/2);\r
                                if(fTriggerData->GetPedestalSubtraction(board)) {\r
                                        if(fCharges[pmNumber]>=(Float_t) fTriggerData->GetPedestalCut(integrator,board,channel)){ \r
                                                fCharges[pmNumber] -= (Float_t) fTriggerData->GetPedestal(integrator,board,channel);\r
@@ -169,10 +215,17 @@ void AliVZEROTriggerSimulator::Run() {
                                fCharges[pmNumber] = 0.;\r
                        }\r
                        \r
-                       Float_t time = digit->Time(); \r
-                       time += fTriggerData->GetDelayHit(board,channel);\r
-                       \r
-                       //AliInfo(Form(" PM nb : %d ; ADC= %d ; TDC= %f  Enable Time %d charge %d",pmNumber,digit->ADC(),time,fTriggerData->GetEnableTiming(board,channel),fTriggerData->GetEnableCharge(board,channel)));\r
+                       Float_t time = digit->Time();\r
+                       time -= fClockOffset[board];\r
+\r
+                       AliDebug(10,Form(" Digit: %f %d %d %d %d %d %d %d %d",digit->Time(),\r
+                                        digit->ChargeADC(8),digit->ChargeADC(9),digit->ChargeADC(10),\r
+                                        digit->ChargeADC(11),digit->ChargeADC(12),digit->ChargeADC(13),\r
+                                        digit->ChargeADC(14),digit->ChargeADC(15)));\r
+                       AliDebug(10,Form(" PM nb : %d ; TDC= %f(%f)  Enable Time %d charge %d inCoin %d charge %f",\r
+                                        pmNumber,time,digit->Time(),\r
+                                        fTriggerData->GetEnableTiming(board,channel),fTriggerData->GetEnableCharge(board,channel),\r
+                                        fBBGate[board]->IsInCoincidence(time),fCharges[pmNumber]));\r
                        fBBFlags[pmNumber] = fTriggerData->GetEnableTiming(board,channel) && fBBGate[board]->IsInCoincidence(time);\r
                        fBGFlags[pmNumber] = fTriggerData->GetEnableTiming(board,channel) && fBGGate[board]->IsInCoincidence(time);\r
                        \r
@@ -185,19 +238,33 @@ void AliVZEROTriggerSimulator::Run() {
        Int_t nBGflagsV0C = 0;\r
        Float_t chargeV0A   = 0.;\r
        Float_t chargeV0C   = 0.;\r
+       Int_t aBBflagsV0A = 0;\r
+       Int_t aBBflagsV0C = 0;\r
+       Int_t aBGflagsV0A = 0;\r
+       Int_t aBGflagsV0C = 0;\r
 \r
        for(int i=0;i<64;i++) {\r
                if(i<32) {\r
                        nBBflagsV0C += fBBFlags[i]; \r
                        nBGflagsV0C += fBGFlags[i];\r
                        chargeV0C += fCharges[i];\r
+                       if (fBBFlags[i]) aBBflagsV0C |= (1 << i);\r
+                       if (fBGFlags[i]) aBGflagsV0C |= (1 << i);\r
                } else {\r
                        nBBflagsV0A += fBBFlags[i]; \r
                        nBGflagsV0A += fBGFlags[i];\r
                        chargeV0A += fCharges[i];\r
+                       if (fBBFlags[i]) aBBflagsV0A |= (1 << (i-32));\r
+                       if (fBGFlags[i]) aBGflagsV0A |= (1 << (i-32));\r
                }\r
                //AliInfo(Form("Ch %d BB=%d BG=%d",i,fBBFlags[i],fBGFlags[i] )); \r
        }\r
+\r
+       // Store the BB and BG flags in the digits tree (user info)\r
+       fDigitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsV0A",aBBflagsV0A));\r
+       fDigitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsV0C",aBBflagsV0C));\r
+       fDigitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsV0A",aBGflagsV0A));\r
+       fDigitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsV0C",aBGflagsV0C));\r
        \r
        // BBA\r
        if(nBBflagsV0A>=fTriggerData->GetBBAThreshold())  SetBBA();\r