Macro to calculate the needed HV values as a function of the required MIP signal.
[u/mrichter/AliRoot.git] / VZERO / AliVZEROTriggerSimulator.cxx
index 788cc81..78c377c 100644 (file)
-/**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- *                                                                        *
- * Author: The ALICE Off-line Project.                                    *
- * Contributors are mentioned in the code where appropriate.              *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          *
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
-
-
-//  Simulate the VZERO Trigger response
-// Use FEE parameters stored in Database
-// Can work on real data or in simulation
-#include "TTree.h"
-#include "TClonesArray.h"
-
-#include "AliLog.h"
-#include "AliCDBManager.h"
-#include "AliCDBEntry.h"
-#include "AliCDBStorage.h"
-#include "AliCDBId.h"
-#include "AliVZEROTriggerData.h"
-#include "AliVZEROLogicalSignal.h"
-#include "AliVZEROTriggerSimulator.h"
-#include "AliVZEROdigit.h"
-
-ClassImp(AliVZEROTriggerSimulator)
-
-//_____________________________________________________________________________
-AliVZEROTriggerSimulator::AliVZEROTriggerSimulator(TTree * digitsTree, TClonesArray* digits) : 
-TObject(),fTriggerData(LoadTriggerData()),fDigitsTree(digitsTree),fDigits(digits),fTriggerWord(0)
-{
-       for(int i=0;i<64;i++) {
-               fBBFlags[i] = fBGFlags[i] = kFALSE;
-               fCharges[i] = 0;
-       }
-       GenerateBBWindows();
-       GenerateBGWindows();
-       for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {
-               fBBLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin1(i),0); 
-               fBGLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin2(i),0); 
-               fBBReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin1(i),0);
-               fBGReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin2(i),0);               
-       }
-       fBBGate[0]->Print();
-       fBBGate[4]->Print();
-}
-//_____________________________________________________________________________
-AliVZEROTriggerSimulator::AliVZEROTriggerSimulator() : 
-TObject(),fTriggerData(LoadTriggerData()),fDigitsTree(NULL),fDigits(NULL),fTriggerWord(0)
-{
-       for(int i=0;i<64;i++) {
-               fBBFlags[i] = fBGFlags[i] = kFALSE;
-               fCharges[i] = 0;
-       }
-       GenerateBBWindows();
-       GenerateBGWindows();
-       for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {
-               fBBLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin1(i),0); 
-               fBGLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin2(i),0); 
-               fBBReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin1(i),0);
-               fBGReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin2(i),0);               
-       }
-       fBBGate[0]->Print();
-       fBBGate[4]->Print();
-}
-
-//_____________________________________________________________________________
-AliVZEROTriggerSimulator::~AliVZEROTriggerSimulator(){
-       if(fBBGate) delete [] fBBGate;
-       if(fBGGate) delete [] fBGGate;
-       if(fBBLatch) delete [] fBBLatch;
-       if(fBBReset) delete [] fBBReset;
-       if(fBGLatch) delete [] fBGLatch;
-       if(fBGReset) delete [] fBGReset;
-}
-
-//_____________________________________________________________________________
-void AliVZEROTriggerSimulator::GenerateBBWindows() 
-{
-       for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {
-               AliVZEROLogicalSignal Clk1BB(fTriggerData->GetClk1Win1(i),fTriggerData->GetDelayClk1Win1(i));
-               AliVZEROLogicalSignal Clk2BB(fTriggerData->GetClk2Win1(i),fTriggerData->GetDelayClk2Win1(i));
-               fBBGate[i] = new AliVZEROLogicalSignal(Clk1BB & Clk2BB);
-       }
-}
-//_____________________________________________________________________________
-void AliVZEROTriggerSimulator::GenerateBGWindows() 
-{
-       for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {
-               AliVZEROLogicalSignal Clk1BG(fTriggerData->GetClk1Win2(i),fTriggerData->GetDelayClk1Win2(i));
-               AliVZEROLogicalSignal Clk2BG(fTriggerData->GetClk2Win2(i),fTriggerData->GetDelayClk2Win2(i));
-               fBGGate[i] = new AliVZEROLogicalSignal(Clk1BG & Clk2BG);
-       }
-}
-
-//_____________________________________________________________________________
-AliVZEROTriggerData * AliVZEROTriggerSimulator::LoadTriggerData() const 
-{
-       // Gets Trigger object for VZERO set
-       AliInfo("Loading Trigger parameters");
-       AliCDBManager *man = AliCDBManager::Instance();
-       
-       
-       AliCDBEntry *entry=0;
-       
-       entry = man->Get("VZERO/Trigger/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");
-               entry = man->Get("VZERO/Trigger/Data",0);
-       }
-       
-       // Retrieval of data in directory VZERO/Calib/Trigger:
-       
-       AliVZEROTriggerData *triggerData = NULL;
-       
-       if (entry) triggerData = (AliVZEROTriggerData*) entry->GetObject();
-       if (!triggerData)  AliError("No Trigger data from database !");
-       
-       return triggerData;
-}
-
-//_____________________________________________________________________________
-void AliVZEROTriggerSimulator::Run() {
-       //AliInfo("Generating VZERO Triggers");
-       
-       // Loop over VZERO entries
-       Int_t nEntries = (Int_t)fDigitsTree->GetEntries();
-       for (Int_t ievt=0; ievt<nEntries; ievt++) {
-               fDigitsTree->GetEvent(ievt);
-               
-               Int_t nDigits = fDigits->GetEntriesFast();
-               
-               for (Int_t iDigit=0; iDigit<nDigits; iDigit++) {
-                       AliVZEROdigit* digit = (AliVZEROdigit*)fDigits->At(iDigit);
-                       
-                       Int_t integrator = digit->Integrator();
-                       Int_t pmNumber   = digit->PMNumber();
-                       Int_t board   = pmNumber / 8;
-                       Int_t channel = pmNumber % 8;
-                       
-                       if(fTriggerData->GetEnableCharge(board,channel)) {
-                               fCharges[pmNumber] = digit->ADC();
-                               if(fTriggerData->GetPedestalSubtraction(board)) 
-                                       if(fCharges[pmNumber]>=fTriggerData->GetPedestalCut(integrator,board,channel)){ 
-                                               fCharges[pmNumber] -= fTriggerData->GetPedestal(integrator,board,channel);
-                                       } else {
-                                               fCharges[pmNumber] = 0;
-                                       }
-                       } else {
-                               fCharges[pmNumber] = 0;
-                       }
-                       
-                       Float_t time = (Float_t)digit->Time() / 10.; // digit->Time() in bin of 100 picoseconds. Divide by 10 to have it in nanoseconds
-                       time += fTriggerData->GetDelayHit(board,channel);
-                       
-                       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)));
-                       fBBFlags[pmNumber] = fTriggerData->GetEnableTiming(board,channel) && fBBGate[board]->IsInCoincidence(time);
-                       fBGFlags[pmNumber] = fTriggerData->GetEnableTiming(board,channel) && fBGGate[board]->IsInCoincidence(time);
-                       
-               } // end of loop over digits
-       } // end of loop over events in digits tree
-       
-       Int_t nBBflagsV0A = 0;
-       Int_t nBBflagsV0C = 0;
-       Int_t nBGflagsV0A = 0;
-       Int_t nBGflagsV0C = 0;
-       Int_t chargeV0A   = 0;
-       Int_t chargeV0C   = 0;
-
-       for(int i=0;i<64;i++) {
-               if(i<32) {
-                       nBBflagsV0C += fBBFlags[i]; 
-                       nBGflagsV0C += fBGFlags[i];
-                       chargeV0C += fCharges[i];
-               } else {
-                       nBBflagsV0A += fBBFlags[i]; 
-                       nBGflagsV0A += fBGFlags[i];
-                       chargeV0A += fCharges[i];
-               }
-               //AliInfo(Form("Ch %d BB=%d BG=%d",i,fBBFlags[i],fBGFlags[i] )); 
-       }
-       
-       // BBA
-       if(nBBflagsV0A>=fTriggerData->GetBBAThreshold())  SetBBA();
-       
-       // BBC
-       if(nBBflagsV0C>=fTriggerData->GetBBCThreshold())  SetBBC();
-
-       // BBA_AND_BBC
-       if(GetBBA() && GetBBC())  SetBBAandBBC();
-       
-       // BBA_OR_BBC
-       if(GetBBA() || GetBBC()) SetBBAorBBC();
-
-       // BGA
-       if(nBGflagsV0A>=fTriggerData->GetBGAThreshold()) SetBGA();
-
-       // BGC
-       if(nBGflagsV0C>=fTriggerData->GetBGCThreshold()) SetBGC();
-       
-       // BGA_AND_BBC (Beam Gas from RB24 side)
-       if(nBBflagsV0C>=fTriggerData->GetBBCForBGThreshold() && GetBGA()) SetBGAandBBC();
-       
-       // BGC_AND_BBA (Beam Gas from RB26 side)
-       if(nBBflagsV0A>=fTriggerData->GetBBAForBGThreshold() && GetBGC()) SetBGCandBBA();
-
-       // CTA1_AND_CTC1 (Centrality trigger 1)
-       if(chargeV0A>=fTriggerData->GetCentralityV0AThrLow() && chargeV0C>=fTriggerData->GetCentralityV0CThrLow()) SetCTA1andCTC1();
-
-       // CTA1_OR_CTC1 (Centrality trigger 1)
-       if(chargeV0A>=fTriggerData->GetCentralityV0AThrLow() || chargeV0C>=fTriggerData->GetCentralityV0CThrLow()) SetCTA1orCTC1();
-       
-       // CTA2_AND_CTC2 (Centrality trigger 2)
-       if(chargeV0A>=fTriggerData->GetCentralityV0AThrHigh() && chargeV0C>=fTriggerData->GetCentralityV0CThrHigh()) SetCTA2andCTC2();
-       
-       // CTA2_OR_CTC2 (Centrality trigger 2)
-       if(chargeV0A>=fTriggerData->GetCentralityV0AThrHigh() || chargeV0C>=fTriggerData->GetCentralityV0CThrHigh()) SetCTA2orCTC2();
-       
-       // MTA_AND_MTC (Multiplicity Trigger)
-       if((nBBflagsV0A<=fTriggerData->GetMultV0AThrHigh() && nBBflagsV0A>=fTriggerData->GetMultV0AThrLow())
-          && (nBBflagsV0C<=fTriggerData->GetMultV0CThrHigh() && nBBflagsV0C>=fTriggerData->GetMultV0CThrLow()) ) 
-               SetMTAandMTC();
-       
-       // MTA_OR_MTC (Multiplicity Trigger)
-       if((nBBflagsV0A<=fTriggerData->GetMultV0AThrHigh() && nBBflagsV0A>=fTriggerData->GetMultV0AThrLow())
-          || (nBBflagsV0C<=fTriggerData->GetMultV0CThrHigh() && nBBflagsV0C>=fTriggerData->GetMultV0CThrLow()) ) 
-               SetMTAorMTC();
-       
-       // BGA_OR_BGC
-       if(GetBGA() || GetBGC()) SetBGAorBGC();
-       
-       // (BGA and BBC) or (BGC and BBA) (Beam Gas from one of the two sides)
-       if(GetBGAandBBC() || GetBGCandBBA()) SetBeamGas();
-
-       AliInfo(Form("BB Flags : V0A = %d  V0C = %d ",nBBflagsV0A, nBBflagsV0C )); 
-       AliInfo(Form("BG Flags : V0A = %d  V0C = %d ",nBGflagsV0A, nBGflagsV0C )); 
-       AliInfo(Form("Charges  : V0A = %d  V0C = %d ",chargeV0A, chargeV0C )); 
-       
-}
+/**************************************************************************\r
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
+ *                                                                        *\r
+ * Author: The ALICE Off-line Project.                                    *\r
+ * Contributors are mentioned in the code where appropriate.              *\r
+ *                                                                        *\r
+ * Permission to use, copy, modify and distribute this software and its   *\r
+ * documentation strictly for non-commercial purposes is hereby granted   *\r
+ * without fee, provided that the above copyright notice appears in all   *\r
+ * copies and that both the copyright notice and this permission notice   *\r
+ * appear in the supporting documentation. The authors make no claims     *\r
+ * about the suitability of this software for any purpose. It is          *\r
+ * provided "as is" without express or implied warranty.                  *\r
+ **************************************************************************/\r
+// \r
+// Class AliVZEROTriggerSimulator\r
+// ------------------------------\r
+//  Simulate the VZERO Trigger response\r
+// Use FEE parameters stored in Database\r
+// Can work on real data or in simulation\r
+//\r
+\r
+#include <TTree.h>\r
+#include <TClonesArray.h>\r
+#include <TParameter.h>\r
+\r
+#include "AliLog.h"\r
+#include "AliCDBManager.h"\r
+#include "AliCDBEntry.h"\r
+#include "AliCDBStorage.h"\r
+#include "AliCDBId.h"\r
+#include "AliVZEROTriggerData.h"\r
+#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
+//_____________________________________________________________________________\r
+AliVZEROTriggerSimulator::AliVZEROTriggerSimulator(TTree * digitsTree, TClonesArray* digits) : \r
+TObject(),fTriggerData(NULL),fDigitsTree(digitsTree),fDigits(digits),fTriggerWord(0)\r
+{\r
+       // constructor\r
+       fTriggerData = LoadTriggerData();\r
+       LoadClockOffset();\r
+       \r
+       for(int i=0;i<64;i++) {\r
+               fBBFlags[i] = fBGFlags[i] = kFALSE;\r
+               fCharges[i] = 0.;\r
+       }\r
+       GenerateBBWindows();\r
+       GenerateBGWindows();\r
+       for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
+               fBBLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin1(i),0); \r
+               fBGLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin2(i),0); \r
+               fBBReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin1(i),0);\r
+               fBGReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin2(i),0);               \r
+       }\r
+}\r
+//_____________________________________________________________________________\r
+AliVZEROTriggerSimulator::AliVZEROTriggerSimulator() : \r
+TObject(),fTriggerData(NULL),fDigitsTree(NULL),fDigits(NULL),fTriggerWord(0)\r
+{\r
+       // Default constructor\r
+       fTriggerData = LoadTriggerData();\r
+       LoadClockOffset();\r
+\r
+       for(int i=0;i<64;i++) {\r
+               fBBFlags[i] = fBGFlags[i] = kFALSE;\r
+               fCharges[i] = 0;\r
+       }\r
+       GenerateBBWindows();\r
+       GenerateBGWindows();\r
+       for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
+               fBBLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin1(i),0); \r
+               fBGLatch[i] = new AliVZEROLogicalSignal(fTriggerData->GetLatchWin2(i),0); \r
+               fBBReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin1(i),0);\r
+               fBGReset[i] = new AliVZEROLogicalSignal(fTriggerData->GetResetWin2(i),0);               \r
+       }\r
+}\r
+\r
+//_____________________________________________________________________________\r
+AliVZEROTriggerSimulator::~AliVZEROTriggerSimulator(){\r
+// Destructor\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
+void AliVZEROTriggerSimulator::GenerateBBWindows() \r
+{\r
+       // Generates the BB observation window\r
+       for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
+               AliVZEROLogicalSignal clk1BB(fTriggerData->GetClk1Win1(i),fTriggerData->GetDelayClk1Win1(i));\r
+               AliVZEROLogicalSignal clk2BB(fTriggerData->GetClk2Win1(i),fTriggerData->GetDelayClk2Win1(i));\r
+               fBBGate[i] = new AliVZEROLogicalSignal(clk1BB & clk2BB);\r
+       }\r
+}\r
+//_____________________________________________________________________________\r
+void AliVZEROTriggerSimulator::GenerateBGWindows() \r
+{\r
+       // Generates the BG observation window\r
+       for (int i=0; i<AliVZEROTriggerData::kNCIUBoards; i++) {\r
+               AliVZEROLogicalSignal clk1BG(fTriggerData->GetClk1Win2(i),fTriggerData->GetDelayClk1Win2(i));\r
+               AliVZEROLogicalSignal clk2BG(fTriggerData->GetClk2Win2(i),fTriggerData->GetDelayClk2Win2(i));\r
+               fBGGate[i] = new AliVZEROLogicalSignal(clk1BG & clk2BG);\r
+       }\r
+}\r
+\r
+//_____________________________________________________________________________\r
+AliVZEROTriggerData * AliVZEROTriggerSimulator::LoadTriggerData() const \r
+{\r
+       // Gets Trigger object for VZERO set\r
+        AliDebug(1,"Loading Trigger parameters");\r
+       AliCDBManager *man = AliCDBManager::Instance();\r
+       \r
+       \r
+       AliCDBEntry *entry=0;\r
+       \r
+       entry = man->Get("VZERO/Trigger/Data");\r
+       if(!entry){\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
+       \r
+       AliVZEROTriggerData *triggerData = NULL;\r
+       \r
+       if (entry) triggerData = (AliVZEROTriggerData*) entry->GetObject();\r
+       if (!triggerData)  AliError("No Trigger data from database !");\r
+       \r
+       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
+       \r
+       // Loop over VZERO entries\r
+       Int_t nEntries = (Int_t)fDigitsTree->GetEntries();\r
+       for (Int_t ievt=0; ievt<nEntries; ievt++) {\r
+               fDigitsTree->GetEvent(ievt);\r
+               \r
+               Int_t nDigits = fDigits->GetEntriesFast();\r
+               \r
+               for (Int_t iDigit=0; iDigit<nDigits; iDigit++) {\r
+                       AliVZEROdigit* digit = (AliVZEROdigit*)fDigits->At(iDigit);\r
+                       \r
+                       Int_t integrator = digit->Integrator();\r
+                       Int_t pmNumber   = digit->PMNumber();\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->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
+                                       } else {\r
+                                               fCharges[pmNumber] = 0.;\r
+                                       }\r
+                               }\r
+                       } else {\r
+                               fCharges[pmNumber] = 0.;\r
+                       }\r
+                       \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
+               } // end of loop over digits\r
+       } // end of loop over events in digits tree\r
+       \r
+       Int_t nBBflagsV0A = 0;\r
+       Int_t nBBflagsV0C = 0;\r
+       Int_t nBGflagsV0A = 0;\r
+       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
+       \r
+       // BBC\r
+       if(nBBflagsV0C>=fTriggerData->GetBBCThreshold())  SetBBC();\r
+\r
+       // BBA_AND_BBC\r
+       if(GetBBA() && GetBBC())  SetBBAandBBC();\r
+       \r
+       // BBA_OR_BBC\r
+       if(GetBBA() || GetBBC()) SetBBAorBBC();\r
+\r
+       // BGA\r
+       if(nBGflagsV0A>=fTriggerData->GetBGAThreshold()) SetBGA();\r
+\r
+       // BGC\r
+       if(nBGflagsV0C>=fTriggerData->GetBGCThreshold()) SetBGC();\r
+       \r
+       // BGA_AND_BBC (Beam Gas from RB24 side)\r
+       if(nBBflagsV0C>=fTriggerData->GetBBCForBGThreshold() && GetBGA()) SetBGAandBBC();\r
+       \r
+       // BGC_AND_BBA (Beam Gas from RB26 side)\r
+       if(nBBflagsV0A>=fTriggerData->GetBBAForBGThreshold() && GetBGC()) SetBGCandBBA();\r
+\r
+       // CTA1_AND_CTC1 (Centrality trigger 1)\r
+       if(chargeV0A>=fTriggerData->GetCentralityV0AThrLow() && chargeV0C>=fTriggerData->GetCentralityV0CThrLow()) SetCTA1andCTC1();\r
+\r
+       // CTA1_OR_CTC1 (Centrality trigger 1)\r
+       if(chargeV0A>=fTriggerData->GetCentralityV0AThrLow() || chargeV0C>=fTriggerData->GetCentralityV0CThrLow()) SetCTA1orCTC1();\r
+       \r
+       // CTA2_AND_CTC2 (Centrality trigger 2)\r
+       if(chargeV0A>=fTriggerData->GetCentralityV0AThrHigh() && chargeV0C>=fTriggerData->GetCentralityV0CThrHigh()) SetCTA2andCTC2();\r
+       \r
+       // CTA2_OR_CTC2 (Centrality trigger 2)\r
+       if(chargeV0A>=fTriggerData->GetCentralityV0AThrHigh() || chargeV0C>=fTriggerData->GetCentralityV0CThrHigh()) SetCTA2orCTC2();\r
+       \r
+       // MTA_AND_MTC (Multiplicity Trigger)\r
+       if((nBBflagsV0A<=fTriggerData->GetMultV0AThrHigh() && nBBflagsV0A>=fTriggerData->GetMultV0AThrLow())\r
+          && (nBBflagsV0C<=fTriggerData->GetMultV0CThrHigh() && nBBflagsV0C>=fTriggerData->GetMultV0CThrLow()) ) \r
+               SetMTAandMTC();\r
+       \r
+       // MTA_OR_MTC (Multiplicity Trigger)\r
+       if((nBBflagsV0A<=fTriggerData->GetMultV0AThrHigh() && nBBflagsV0A>=fTriggerData->GetMultV0AThrLow())\r
+          || (nBBflagsV0C<=fTriggerData->GetMultV0CThrHigh() && nBBflagsV0C>=fTriggerData->GetMultV0CThrLow()) ) \r
+               SetMTAorMTC();\r
+       \r
+       // BGA_OR_BGC\r
+       if(GetBGA() || GetBGC()) SetBGAorBGC();\r
+       \r
+       // (BGA and BBC) or (BGC and BBA) (Beam Gas from one of the two sides)\r
+       if(GetBGAandBBC() || GetBGCandBBA()) SetBeamGas();\r
+\r
+//     AliInfo(Form("BB Flags : V0A = %d  V0C = %d ",nBBflagsV0A, nBBflagsV0C )); \r
+//     AliInfo(Form("BG Flags : V0A = %d  V0C = %d ",nBGflagsV0A, nBGflagsV0C )); \r
+//     AliInfo(Form("Charges  : V0A = %d  V0C = %d ",chargeV0A, chargeV0C )); \r
+       \r
+}\r
+\r
+\r
+\r