LCOV - code coverage report
Current view: top level - AD/ADsim - AliADTriggerSimulator.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 167 0.6 %
Date: 2016-06-14 17:26:59 Functions: 1 17 5.9 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : // 
      16             : // Class AliADTriggerSimulator
      17             : // ------------------------------
      18             : //  Simulate the AD Trigger response
      19             : // Use FEE parameters stored in Database
      20             : // Can work on real data or in simulation
      21             : //
      22             : 
      23             : #include <TTree.h>
      24             : #include <TClonesArray.h>
      25             : #include <TParameter.h>
      26             : 
      27             : #include "AliLog.h"
      28             : #include "AliCDBManager.h"
      29             : #include "AliCDBEntry.h"
      30             : #include "AliCDBStorage.h"
      31             : #include "AliCDBId.h"
      32             : #include "AliADCalibData.h"
      33             : #include "AliADLogicalSignal.h"
      34             : #include "AliADTriggerSimulator.h"
      35             : #include "AliADdigit.h"
      36             : #include "AliADConst.h"
      37             : #include "AliCTPTimeParams.h"
      38             : 
      39          12 : ClassImp(AliADTriggerSimulator)
      40             : 
      41             : //_____________________________________________________________________________
      42             : AliADTriggerSimulator::AliADTriggerSimulator(TTree * digitsTree, TClonesArray* digits) : 
      43           0 : TObject(),fCalibData(NULL),fDigitsTree(digitsTree),fDigits(digits),fTriggerWord(0)
      44           0 : {
      45             :         // constructor
      46           0 :         fCalibData = LoadCalibData();
      47           0 :         LoadClockOffset();
      48             :         
      49           0 :         for(int i=0;i<16;i++) {
      50           0 :                 fBBFlags[i] = fBGFlags[i] = kFALSE;
      51           0 :                 fCharges[i] = 0;
      52           0 :                 fTime[i] = 0;
      53             :         }
      54           0 :         GenerateBCMask();
      55           0 :         GenerateBBWindows();
      56           0 :         GenerateBGWindows();
      57             :                         
      58           0 : }
      59             : //_____________________________________________________________________________
      60             : AliADTriggerSimulator::AliADTriggerSimulator() : 
      61           0 : TObject(),fCalibData(NULL),fDigitsTree(NULL),fDigits(NULL),fTriggerWord(0)
      62           0 : {
      63             :         // Default constructor
      64           0 :         fCalibData = LoadCalibData();
      65           0 :         LoadClockOffset();
      66             : 
      67           0 :         for(int i=0;i<16;i++) {
      68           0 :                 fBBFlags[i] = fBGFlags[i] = kFALSE;
      69           0 :                 fCharges[i] = 0;
      70           0 :                 fTime[i] = 0;
      71             :         }
      72           0 :         GenerateBCMask();
      73           0 :         GenerateBBWindows();
      74           0 :         GenerateBGWindows();    
      75           0 : }
      76             : 
      77             : //_____________________________________________________________________________
      78           0 : AliADTriggerSimulator::~AliADTriggerSimulator(){
      79             : // Destructor
      80           0 :   for (Int_t i=0; i<kNCIUBoards; i++) {
      81           0 :     delete fBBGate[i];
      82           0 :     delete fBGGate[i];
      83           0 :     delete fBCMask[i];
      84             :   }
      85           0 : }
      86             : 
      87             : //_____________________________________________________________________________
      88             : void AliADTriggerSimulator::GenerateBCMask() 
      89             : {
      90             :   // Generates the BC mask
      91             :   // Gate at central clock 25ns wide
      92           0 :   for (Int_t i=0; i<kNCIUBoards; i++) {
      93           0 :           fBCMask[i] = new AliADLogicalSignal();
      94           0 :           fBCMask[i]->SetStartTime(fWindowOffset[i]);
      95           0 :           fBCMask[i]->SetStopTime(fWindowOffset[i]+25.0);
      96             :   }    
      97             : 
      98           0 : }
      99             : 
     100             : 
     101             : //_____________________________________________________________________________
     102             : void AliADTriggerSimulator::GenerateBBWindows() 
     103             : {
     104             :   // Generates the BB observation window
     105             :   // In case gates are open the windows are equal to 25ns
     106           0 :   if (AreGatesOpen()) {
     107           0 :         for (Int_t i=0; i<kNCIUBoards; i++) {
     108           0 :                 fBBGate[i] = new AliADLogicalSignal();
     109           0 :                 fBBGate[i]->SetStartTime(fWindowOffset[i]);
     110           0 :                 fBBGate[i]->SetStopTime(fWindowOffset[i]+25.0);
     111             :         }    
     112           0 :   }
     113             :   else {
     114           0 :         for (Int_t i=0; i<kNCIUBoards; i++) {
     115           0 :                 AliADLogicalSignal clk1BB(fCalibData->GetClk1Win1(i),fCalibData->GetDelayClk1Win1(i),fCalibData->GetLatchWin1(i),fCalibData->GetResetWin1(i));
     116           0 :                 AliADLogicalSignal clk2BB(fCalibData->GetClk2Win1(i),fCalibData->GetDelayClk2Win1(i),fCalibData->GetLatchWin1(i),fCalibData->GetResetWin1(i));
     117           0 :                 fBBGate[i] = new AliADLogicalSignal(clk1BB & clk2BB);
     118           0 :                 fBBGate[i]->SetStartTime(fBBGate[i]->GetStartTime()+fWindowOffset[i]);
     119           0 :                 fBBGate[i]->SetStopTime(fBBGate[i]->GetStopTime()+fWindowOffset[i]);
     120             :                                         
     121           0 :         }
     122             :   }
     123           0 : }
     124             : //_____________________________________________________________________________
     125             : void AliADTriggerSimulator::GenerateBGWindows() 
     126             : {
     127             :   // Generates the BG observation window
     128             :   // In case gates are open the windows are equal to 25ns
     129           0 :   if (AreGatesOpen()) {
     130           0 :         for (Int_t i=0; i<kNCIUBoards; i++) {
     131           0 :                 fBGGate[i] = new AliADLogicalSignal();
     132           0 :                 fBGGate[i]->SetStartTime(fWindowOffset[i]);
     133           0 :                 fBGGate[i]->SetStopTime(fWindowOffset[i]+25.0);
     134             :         }    
     135           0 :   }
     136             :   else {
     137           0 :         for (Int_t i=0; i<kNCIUBoards; i++) {
     138           0 :                 AliADLogicalSignal clk1BG(fCalibData->GetClk1Win2(i),fCalibData->GetDelayClk1Win2(i),fCalibData->GetLatchWin2(i),fCalibData->GetResetWin2(i));
     139           0 :                 clk1BG.SetStartTime(clk1BG.GetStartTime()+2);
     140           0 :                 clk1BG.SetStopTime(clk1BG.GetStopTime()+2);
     141           0 :                 AliADLogicalSignal clk2BG(fCalibData->GetClk2Win2(i),fCalibData->GetDelayClk2Win2(i),fCalibData->GetLatchWin2(i),fCalibData->GetResetWin2(i));
     142           0 :                 clk2BG.SetStartTime(clk2BG.GetStartTime()-2);
     143           0 :                 clk2BG.SetStopTime(clk2BG.GetStopTime()-2);
     144           0 :                 fBGGate[i] = new AliADLogicalSignal(clk1BG & clk2BG);
     145           0 :                 fBGGate[i]->SetStartTime(fBGGate[i]->GetStartTime()+fWindowOffset[i]);
     146           0 :                 fBGGate[i]->SetStopTime(fBGGate[i]->GetStopTime()+fWindowOffset[i]);      
     147           0 :         }
     148             :   }
     149           0 : }
     150             : 
     151             : //_____________________________________________________________________________
     152             : AliADCalibData * AliADTriggerSimulator::LoadCalibData() const 
     153             : {
     154             :         // Gets Trigger object for AD set
     155           0 :         AliDebug(1,"Loading Trigger parameters");
     156           0 :         AliCDBManager *man = AliCDBManager::Instance();
     157             :         
     158             :         
     159             :         AliCDBEntry *entry=0;
     160             :         
     161           0 :         entry = man->Get("AD/Calib/Data");
     162           0 :         if(!entry){
     163           0 :                 AliFatal("Load of calibration data from default storage failed!");
     164           0 :                 return NULL;
     165             :         }
     166             :         
     167             :         AliADCalibData *calibData = NULL;
     168             :         
     169           0 :         if (entry) calibData = (AliADCalibData*) entry->GetObject();
     170           0 :         if (!calibData)  AliError("No Trigger data from database !");
     171             :         
     172             :         return calibData;
     173           0 : }
     174             : 
     175             : 
     176             : //_____________________________________________________________________________
     177             : void AliADTriggerSimulator::LoadClockOffset()
     178             : {
     179             :   // This method is used in order to
     180             :   // retrieve the TDC clock offset including
     181             :   // roll-over, trig count and CTP L0->L1 delay
     182             : 
     183           0 :   AliCDBEntry *entry0 = AliCDBManager::Instance()->Get("AD/Calib/Data");
     184           0 :   if (!entry0) {
     185           0 :     AliFatal("AD Calib object is not found in OCDB !");
     186           0 :     return;
     187             :   }
     188           0 :   AliADCalibData *calibdata = (AliADCalibData*) entry0->GetObject();
     189             : 
     190           0 :   AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
     191           0 :   if (!entry) {
     192           0 :     AliFatal("CTP timing parameters are not found in OCDB !");
     193           0 :     return;
     194             :   }
     195           0 :   AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();
     196           0 :   Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;
     197             : 
     198           0 :   AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
     199           0 :   if (!entry1) {
     200           0 :     AliFatal("CTP time-alignment is not found in OCDB !");
     201           0 :     return;
     202             :   }
     203           0 :   AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();
     204           0 :   l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);
     205             :   //Start of the central clock in HPTDC time
     206           0 :   for(Int_t board = 0; board < kNCIUBoards; ++board) {
     207           0 :     fWindowOffset[board] = (((Float_t)calibdata->GetRollOver(board)-
     208           0 :                             (Float_t)calibdata->GetTriggerCountOffset(board))*25.0
     209           0 :                              -l1Delay
     210           0 :                              -kADOffset);
     211           0 :     AliDebug(1,Form("Board %d Offset %f",board,fWindowOffset[board]));
     212             :   }
     213           0 : }
     214             : //_____________________________________________________________________________
     215             : void AliADTriggerSimulator::FillFlags(Bool_t *bbFlag, Bool_t *bgFlag, Float_t time[16]){
     216             : 
     217           0 :   for(Int_t i = 0; i<16; i++){
     218           0 :         Int_t board   = AliADCalibData::GetBoardNumber(i);
     219             :         
     220           0 :         Bool_t inBCmask = fBCMask[board]->IsInCoincidence(time[i]);
     221           0 :         Bool_t inBBwindow = fBBGate[board]->IsInCoincidence(time[i]);
     222           0 :         Bool_t inBGwindow = fBGGate[board]->IsInCoincidence(time[i]);
     223             :         
     224             :         /*/
     225             :         Bool_t inBBwindow = kFALSE;
     226             :         Bool_t inBGwindow = kFALSE;
     227             :         
     228             :         AliADLogicalSignal fBBGateShifted;
     229             :         AliADLogicalSignal fBGGateShifted;
     230             :         for(Int_t j=-10; j<=10; j++){
     231             :                 fBBGateShifted.SetStartTime(fBBGate[board]->GetStartTime() + 25*j);
     232             :                 fBBGateShifted.SetStopTime(fBBGate[board]->GetStopTime() + 25*j);
     233             :                 fBGGateShifted.SetStartTime(fBGGate[board]->GetStartTime() + 25*j);
     234             :                 fBGGateShifted.SetStopTime(fBGGate[board]->GetStopTime() + 25*j);
     235             :                 
     236             :                 if(fBBGateShifted.IsInCoincidence(time[i])) inBBwindow = kTRUE;
     237             :                 if(fBGGateShifted.IsInCoincidence(time[i])) inBGwindow = kTRUE;
     238             :                 }
     239             :         /*/
     240           0 :         bbFlag[i] = inBBwindow;
     241           0 :         bgFlag[i] = inBGwindow;
     242             :         
     243             :         //AliInfo(Form("Ch %d Time=%.1f BCM=%d BB=%d BG=%d",i,time[i],inBCmask,bbFlag[i],bgFlag[i] ));
     244             :         }
     245           0 : }
     246             : //_____________________________________________________________________________
     247             : void AliADTriggerSimulator::Run() {
     248             : //      AliInfo("Generating AD Triggers");
     249             : //      Print("");
     250             :         
     251             :         // Loop over AD entries
     252           0 :         Int_t nEntries = (Int_t)fDigitsTree->GetEntries();
     253           0 :         for (Int_t ievt=0; ievt<nEntries; ievt++) {
     254           0 :                 fDigitsTree->GetEvent(ievt);
     255             :                 
     256           0 :                 Int_t nDigits = fDigits->GetEntriesFast();
     257           0 :                 for (Int_t iDigit=0; iDigit<nDigits; iDigit++) {
     258           0 :                         AliADdigit* digit = (AliADdigit*)fDigits->At(iDigit);
     259             :                         
     260           0 :                         Int_t integrator = digit->Integrator();
     261           0 :                         Int_t pmNumber   = digit->PMNumber();
     262           0 :                         Int_t board   = AliADCalibData::GetBoardNumber(pmNumber);
     263           0 :                         if (board < 0) continue;
     264             :                         
     265           0 :                         if(fCalibData->GetEnableCharge(pmNumber)) {
     266           0 :                                 fCharges[pmNumber] = digit->ChargeADC(kADNClocks/2);
     267           0 :                                 if(fCalibData->GetPedestalSubtraction(board)) {
     268           0 :                                         if(fCharges[pmNumber]>=(Float_t) fCalibData->GetOnlinePedestalCut(integrator,pmNumber)){ 
     269           0 :                                                 fCharges[pmNumber] -= (Float_t) fCalibData->GetOnlinePedestal(integrator,pmNumber);
     270           0 :                                         } else {
     271           0 :                                                 fCharges[pmNumber] = 0.;
     272             :                                         }
     273             :                                 }
     274             :                         } else {
     275           0 :                                 fCharges[pmNumber] = 0.;
     276             :                         }
     277             :                         
     278           0 :                         fTime[pmNumber] = digit->Time();
     279             :                         
     280           0 :                 } // end of loop over digits
     281             :         } // end of loop over events in digits tree
     282           0 :         FillFlags(fBBFlags,fBGFlags,fTime);
     283             :         
     284             :         Int_t nBBflagsADA = 0;
     285             :         Int_t nBBflagsADC = 0;
     286             :         Int_t nBGflagsADA = 0;
     287             :         Int_t nBGflagsADC = 0;
     288             :         Float_t chargeADA   = 0.;
     289             :         Float_t chargeADC   = 0.;
     290             : 
     291           0 :         for(int i=0;i<16;i++) {
     292           0 :                 if(i<8) chargeADC += fCharges[i];
     293           0 :                 else chargeADA += fCharges[i];  
     294             :         }
     295             :         
     296           0 :         for(Int_t iChannel=0; iChannel<4; iChannel++) {//Loop over pairs of pads
     297             :             //Enable time is used to turn off the coincidence 
     298           0 :             if((!fCalibData->GetEnableTiming(iChannel) || fBBFlags[iChannel]) && (!fCalibData->GetEnableTiming(iChannel+4) || fBBFlags[iChannel+4])) nBBflagsADC++;
     299           0 :             if((!fCalibData->GetEnableTiming(iChannel) || fBGFlags[iChannel]) && (!fCalibData->GetEnableTiming(iChannel+4) || fBGFlags[iChannel+4])) nBGflagsADC++;
     300             : 
     301           0 :             if((!fCalibData->GetEnableTiming(iChannel+8) || fBBFlags[iChannel+8]) && (!fCalibData->GetEnableTiming(iChannel+12) || fBBFlags[iChannel+12])) nBBflagsADA++;
     302           0 :             if((!fCalibData->GetEnableTiming(iChannel+8) || fBGFlags[iChannel+8]) && (!fCalibData->GetEnableTiming(iChannel+12) || fBGFlags[iChannel+12])) nBGflagsADA++;
     303             :         }
     304             : 
     305             :         // BBA
     306           0 :         if(nBBflagsADA>=fCalibData->GetBBAThreshold())  SetBBA();
     307             :         
     308             :         // BBC
     309           0 :         if(nBBflagsADC>=fCalibData->GetBBCThreshold())  SetBBC();
     310             : 
     311             :         // BBA_AND_BBC
     312           0 :         if(GetBBA() && GetBBC())  SetBBAandBBC();
     313             :         
     314             :         // BBA_OR_BBC
     315           0 :         if(GetBBA() || GetBBC()) SetBBAorBBC();
     316             : 
     317             :         // BGA
     318           0 :         if(nBGflagsADA>=fCalibData->GetBGAThreshold()) SetBGA();
     319             : 
     320             :         // BGC
     321           0 :         if(nBGflagsADC>=fCalibData->GetBGCThreshold()) SetBGC();
     322             :         
     323             :         // BGA_AND_BBC (Beam Gas from RB24 side)
     324           0 :         if(nBBflagsADC>=fCalibData->GetBBCForBGThreshold() && GetBGA()) SetBGAandBBC();
     325             :         
     326             :         // BGC_AND_BBA (Beam Gas from RB26 side)
     327           0 :         if(nBBflagsADA>=fCalibData->GetBBAForBGThreshold() && GetBGC()) SetBGCandBBA();
     328             : 
     329             :         
     330             :         // MTA_AND_MTC (Multiplicity Trigger)
     331           0 :         if((nBBflagsADA<=fCalibData->GetMultADAThrHigh() && nBBflagsADA>=fCalibData->GetMultADAThrLow())
     332           0 :            && (nBBflagsADC<=fCalibData->GetMultADCThrHigh() && nBBflagsADC>=fCalibData->GetMultADCThrLow()) ) 
     333           0 :                 SetMTAandMTC();
     334             :         
     335             :         // MTA_OR_MTC (Multiplicity Trigger)
     336           0 :         if((nBBflagsADA<=fCalibData->GetMultADAThrHigh() && nBBflagsADA>=fCalibData->GetMultADAThrLow())
     337           0 :            || (nBBflagsADC<=fCalibData->GetMultADCThrHigh() && nBBflagsADC>=fCalibData->GetMultADCThrLow()) ) 
     338           0 :                 SetMTAorMTC();
     339             :         
     340             :         // BGA_OR_BGC
     341           0 :         if(GetBGA() || GetBGC()) SetBGAorBGC();
     342             :         
     343             :         // (BGA and BBC) or (BGC and BBA) (Beam Gas from one of the two sides)
     344           0 :         if(GetBGAandBBC() || GetBGCandBBA()) SetBeamGas();
     345             : 
     346             :         //AliInfo(Form("BB Flags : ADA = %d  ADC = %d ",nBBflagsADA, nBBflagsADC )); 
     347             :         //AliInfo(Form("BG Flags : ADA = %d  ADC = %d ",nBGflagsADA, nBGflagsADC )); 
     348             :         //AliInfo(Form("Charges  : ADA = %d  ADC = %d ",chargeADA, chargeADC )); 
     349             :         
     350           0 : }
     351             : 
     352             : //_____________________________________________________________________________
     353             : Bool_t AliADTriggerSimulator::AreGatesOpen() const {
     354             :   // The method check if the gates are suppossed to be open
     355             :   // (corresponding to 'Test Window' flag in DCS).
     356             :   // Since the flag is not stored in OCDB, we just check if
     357             :   // all the clock delays are 0 or not.
     358             :   // This rules should be followed when setting up the detector
     359             :   // at the level of DCS
     360             : 
     361           0 :   for (int i=0; i<kNCIUBoards; i++) {
     362           0 :     if (fCalibData->GetDelayClk1Win1(i)!=0 ||
     363           0 :         fCalibData->GetDelayClk2Win1(i)!=0 ||
     364           0 :         fCalibData->GetDelayClk1Win2(i)!=0 ||
     365           0 :         fCalibData->GetDelayClk2Win2(i)!=0)
     366           0 :       return kFALSE;
     367             :   }
     368           0 :   return kTRUE;
     369           0 : }
     370             : 
     371             : //_____________________________________________________________________________
     372             : void AliADTriggerSimulator::Print(Option_t* /* opt */) const
     373             : {
     374             :   // Prints the trigger windows as
     375             :   // initialized from the OCDB
     376           0 :   for (int i=0; i<kNCIUBoards; i++) {
     377           0 :     std::cout << "Board=" << i << "   BB (" << fBBGate[i]->GetStartTime() << " -> " << fBBGate[i]->GetStopTime() << ")   BG (" << fBGGate[i]->GetStartTime() << " -> " << fBGGate[i]->GetStopTime() << ")" << std::endl;
     378             :   }
     379           0 :   std::cout << std::endl;
     380           0 : }
     381             : 
     382             : 

Generated by: LCOV version 1.11