]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFTrigger.cxx
Using detector quality flag (taken from ALICE logbook) to decide whether to rpodcue...
[u/mrichter/AliRoot.git] / TOF / AliTOFTrigger.cxx
index df5e183798ee883f69add41a417290c077b55514..efea00c0616ad4ca332af9a12d971ca1aa092c8b 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <TClonesArray.h>
 #include <TTree.h>
+#include <TMath.h>
 
 #include "AliLoader.h"
 #include "AliLog.h"
@@ -54,6 +55,8 @@
 
 extern AliRun* gAlice;
 
+AliTOFTriggerMask* AliTOFTrigger:: fTOFTrigMap=NULL;
+AliTOFTriggerMask* AliTOFTrigger:: fTOFTrigMask=NULL;
 //-------------------------------------------------------------------------
 ClassImp(AliTOFTrigger)
 
@@ -76,7 +79,9 @@ ClassImp(AliTOFTrigger)
     fNCrateOn(0),
     fNMaxipadOn(0),
     fNMaxipadOnAll(0),
-    fTOFTrigMask(0)
+    fStartTimeHit(0.0),
+    fTimeWidthTrigger(25.0)
+
 {
   //main ctor
   for (Int_t i=0;i<kNCTTM;i++) fLTMarray[i] = kFALSE;
@@ -102,11 +107,13 @@ ClassImp(AliTOFTrigger)
   SetName("TOF");
   CreateInputs();
 
+  if(!fTOFTrigMap) fTOFTrigMap = new AliTOFTriggerMask();
+
 }
 
 //----------------------------------------------------------------------
 
-AliTOFTrigger::AliTOFTrigger(Int_t HighMultTh, Int_t ppMBTh, Int_t MultiMuonTh, Int_t UPTh, Float_t deltaminpsi, Float_t deltamaxpsi, Float_t deltaminro, Float_t deltamaxro, Int_t stripWindow) :
+AliTOFTrigger::AliTOFTrigger(Int_t HighMultTh, Int_t ppMBTh, Int_t MultiMuonTh, Int_t UPTh, Float_t deltaminpsi, Float_t deltamaxpsi, Float_t deltaminro, Float_t deltamaxro, Int_t stripWindow,Float_t startTimeWindow,Float_t widthTimeWindow) :
   AliTriggerDetector(),
   fHighMultTh(HighMultTh),
   fppMBTh(ppMBTh),
@@ -124,7 +131,8 @@ AliTOFTrigger::AliTOFTrigger(Int_t HighMultTh, Int_t ppMBTh, Int_t MultiMuonTh,
   fNCrateOn(0),
   fNMaxipadOn(0),
   fNMaxipadOnAll(0),
-  fTOFTrigMask(0)
+  fStartTimeHit(startTimeWindow),
+  fTimeWidthTrigger(widthTimeWindow)
 {
   //ctor with thresholds for triggers
   for (Int_t i=0;i<kNCTTM;i++) fLTMarray[i] = kFALSE;
@@ -147,6 +155,8 @@ AliTOFTrigger::AliTOFTrigger(Int_t HighMultTh, Int_t ppMBTh, Int_t MultiMuonTh,
 
   SetName("TOF");
   CreateInputs();
+
+  if(!fTOFTrigMap) fTOFTrigMap = new AliTOFTriggerMask();
 }
 
 
@@ -170,8 +180,7 @@ AliTOFTrigger::AliTOFTrigger(const AliTOFTrigger & tr):
   fSel4(tr.fSel4),
   fNCrateOn(tr.fNCrateOn),
   fNMaxipadOn(tr.fNMaxipadOn),
-  fNMaxipadOnAll(tr.fNMaxipadOnAll),
-  fTOFTrigMask(0)
+  fNMaxipadOnAll(tr.fNMaxipadOnAll)
 {
   //copy ctor
   for (Int_t i=0;i<kNCTTM;i++) fLTMarray[i] = kFALSE;
@@ -192,11 +201,6 @@ AliTOFTrigger::AliTOFTrigger(const AliTOFTrigger & tr):
       fPowerMask[i] = fPowerMask[i-1]*2;
   }
 
-  if(tr.fTOFTrigMask){
-      fTOFTrigMask = new AliTOFTriggerMask();  
-      fTOFTrigMask->SetTriggerMaskArray(tr.fTOFTrigMask->GetTriggerMaskArray());
-  }
-
   SetName(tr.GetName());
   //fInputs=&(tr.GetInputs());
   CreateInputs();
@@ -212,13 +216,14 @@ void AliTOFTrigger::CreateInputs()
   // Do not create inputs again!!
   if( fInputs.GetEntriesFast() > 0 ) return;
 
-  LoadActiveMask();
+  //LoadActiveMask();
 
   fInputs.AddLast(new AliTriggerInput("TOF_Cosmic_MultiMuon_L0","TOF",0));
   fInputs.AddLast(new AliTriggerInput("0OIN","TOF",0)); // was "TOF_pp_MB_L0"
   fInputs.AddLast(new AliTriggerInput("0OM2","TOF",0)); // was "TOF_PbPb_MB2_L0"
   fInputs.AddLast(new AliTriggerInput("0OM3","TOF",0)); // was "TOF_PbPb_MB3_L0"
   fInputs.AddLast(new AliTriggerInput("0OUP","TOF",0)); // was "TOF_UltraPer_Coll_L0"
+  fInputs.AddLast(new AliTriggerInput("0OMU","TOF",0)); // new trigger (150 < DeltaPhi < 180) and 2 <= N_pad <= 6
 
   fInputs.AddLast(new AliTriggerInput("0OHM","TOF",0)); // was "TOF_High_Mult_L0"
   fInputs.AddLast(new AliTriggerInput("TOF_Jet_L1","TOF",0));
@@ -227,6 +232,9 @@ void AliTOFTrigger::CreateInputs()
 
 //----------------------------------------------------------------------
 void AliTOFTrigger::Trigger() {
+  fTOFTrigMap->ResetMask();
+  if(!fTOFTrigMask) LoadActiveMask();
+
   //triggering method
   fSel1=0;
   fSel2=0;
@@ -234,6 +242,7 @@ void AliTOFTrigger::Trigger() {
   fSel4=0;
 
   CreateLTMMatrix();
+
   Int_t nchonFront = 0;
   Int_t nchonBack = 0;
   Int_t nchonTot = 0;
@@ -251,13 +260,19 @@ void AliTOFTrigger::Trigger() {
 
   for (Int_t i=0;i<kNCTTM;i++){
     for (Int_t j=0;j<kNCTTMchannels;j++){
-      if (fCTTMmatrixFront[i][j]) nchonFront++;
+      if (fCTTMmatrixFront[i][j]){
+       nchonFront++;
+       fTOFTrigMap->SetON(i,j);
+      }
     }
   }
 
   for (Int_t i=kNCTTM;i<(kNCTTM*2);i++){
     for (Int_t j=0;j<kNCTTMchannels;j++){
-      if (fCTTMmatrixBack[i-kNCTTM][j]) nchonBack++;
+      if (fCTTMmatrixBack[i-kNCTTM][j]){
+       nchonBack++;
+       fTOFTrigMap->SetON(i,j);
+      }
     }
   }
 
@@ -422,8 +437,15 @@ void AliTOFTrigger::Trigger() {
                          //printf("trigger On with AntiDeSlot \n");
                      } 
                      
-                 } 
-                 
+                     if(nchonTot >= 2 && nchonTot <= 6){
+                       if(DeSlots >= 15 && DeSlots <= 18){
+                         SetInput("0OMU");
+                       }
+                       else if(AntiDeSlots >= 15 && AntiDeSlots <= 18){
+                         SetInput("0OMU");
+                       }       
+                     }               
+                 }
              }    
          }
       }
@@ -435,6 +457,7 @@ void AliTOFTrigger::CreateLTMMatrix() {
   //creating LTMMatrix
   //initialization
   CreateLTMMatrixFromDigits();
+  CreateCTTMMatrix();
 }
 
 //-------------------------------------------------------------------------
@@ -500,14 +523,25 @@ void AliTOFTrigger::CreateLTMMatrixFromDigits() {
     Int_t indexLTM[2] = {-1,-1};
     GetLTMIndex(detind,indexLTM);
 
-    fLTMmatrix[indexLTM[0]][indexLTM[1]] = kTRUE;
+    //Float_t timedigit = digit->GetTdc()*AliTOFGeometry::TdcBinWidth()*1E-3; // decalibrated time digit in ns
+    Float_t timedigit = digit->GetTdcND()*AliTOFGeometry::TdcBinWidth()*1E-3; // time digit in ns
+
+    Float_t pos[3];
+    AliTOFGeometry::GetPosPar(detind, pos);
+    Float_t length = 0.;
+    for (Int_t ic = 0; ic < 3; ic++) length += pos[ic] * pos[ic];
+    length = TMath::Sqrt(length);
+    timedigit -= length * 0.0333564095198152043; // subtract the minimal time in ns for the current channel
+
+    if(timedigit > fStartTimeHit - 0.5 && timedigit < fStartTimeHit + fTimeWidthTrigger - 0.5)
+      fLTMmatrix[indexLTM[0]][indexLTM[1]] = kTRUE;
+
 //    fLTMarray[indexLTM[0]%36] = kTRUE; //dimensione MAX array 36 = kNCTTM 
-    }
+  }
 
 
   tofLoader->UnloadDigits();
   //   rl->UnloadgAlice();
-  CreateCTTMMatrix();
 
 }
 
@@ -517,6 +551,7 @@ void AliTOFTrigger::CreateLTMMatrixFromRaw(AliRawReader *fRawReader) {
   //
   // Create LTM matrix by TOF raw data
   //
+  fTOFTrigMap->ResetMask();
 
   //initialization
   for (Int_t i=0;i<kNLTM;i++){
@@ -609,7 +644,123 @@ void AliTOFTrigger::CreateLTMMatrixFromRaw(AliRawReader *fRawReader) {
   }
 
 }
+//-----------------------------------------------------------------------------
+void AliTOFTrigger::PrepareTOFMapFromRaw(AliRawReader *fRawReader,Int_t deltaBC) {
+  //
+  // Create LTM matrix by TOF raw data
+  //
+  if(!fTOFTrigMap) fTOFTrigMap = new AliTOFTriggerMask();
+  fTOFTrigMap->ResetMask();
+  LoadActiveMask();
+
+  if(fRawReader){
+    AliTOFRawStream * tofRawStream = new AliTOFRawStream();
+
+    tofRawStream->SetRawReader(fRawReader);
+        
+    TClonesArray staticRawData("AliTOFrawData",10000);
+    staticRawData.Clear();
+    TClonesArray * clonesRawData = &staticRawData;
+    
+    Int_t indexDDL = 0;
+    Int_t iRawData = 0;
+    AliTOFrawData *tofRawDatum = 0;
+    for (indexDDL=0; indexDDL<AliDAQ::NumberOfDdls("TOF"); indexDDL++) {
+      
+      fRawReader->Reset();
+      tofRawStream->LoadRawDataBuffersV2(indexDDL);
+      
+      clonesRawData = tofRawStream->GetRawData();
+      for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
+       
+        tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
+       
+        //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
+        if (tofRawDatum->GetTOF()==-1) continue;
+
+       Int_t nTRM = tofRawDatum->GetTRM();
+       Int_t iChain = tofRawDatum->GetTRMchain();
+       Int_t iTDC = tofRawDatum->GetTDC();
+       Int_t iCH=tofRawDatum->GetTDCchannel();
+
+       if(nTRM==3 && iTDC>=12 && iTDC<=14 && indexDDL%2==1){ // DDL number to LTM number mapping
+         Int_t iLTMindex=-1;
+         Int_t iChannelIndex=-1;
+         switch(indexDDL%AliTOFGeometry::NDDL()){
+         case 1:
+           iLTMindex=1;
+           break;
+         case 3:
+           iLTMindex=36;
+           break;
+         default:
+           break;
+         }
+         iLTMindex+=2*(Int_t)(indexDDL/AliTOFGeometry::NDDL());
+         if(iChain==0 && indexDDL<36)
+           iLTMindex--;
+         if(iChain==0 && indexDDL>=36)
+           iLTMindex++;
+         iChannelIndex=iCH+iTDC*AliTOFGeometry::NCh()-12*AliTOFGeometry::NCh();
+         Int_t index[2]={iLTMindex,iChannelIndex};
+         
+         
+         if(fTOFTrigMask->IsON(index[0],index[1]) && TMath::Abs(tofRawDatum->GetTOF()-deltaBC) < 400) fTOFTrigMap->SetON(index[0],index[1]);
+       }
+       
+        tofRawDatum = 0;
+      } // while loop
+
+      clonesRawData->Clear();
+
+    } // DDL Loop
+
+
+    delete tofRawStream;
+    tofRawStream = NULL;
+
+  }
+
+}
+//-----------------------------------------------------------------------------
+void AliTOFTrigger::PrepareTOFMapFromDigit(TTree *treeD) {
+  if(!fTOFTrigMap) fTOFTrigMap = new AliTOFTriggerMask();
+  LoadActiveMask();
+
+  fTOFTrigMap->ResetMask();
+  if (treeD == 0x0) {
+    return;
+  }
 
+  TBranch *branch = treeD->GetBranch("TOF");
+  if (!branch) {
+    return;
+  }
+  TClonesArray *tofDigits =new TClonesArray("AliTOFdigit",  1000);
+  branch->SetAddress(&tofDigits);
+  treeD->GetEvent(0);
+  Int_t ndigits = tofDigits->GetEntriesFast();
+  Int_t detind[5]; //detector indexes: 0 -> sector
+  //                                   1 -> plate(modulo)
+  //                                   2 -> strip
+  //                                   3 -> padz
+  //                                   4 -> padx
+
+  for (Int_t i=0;i<ndigits;i++){
+    AliTOFdigit * digit = (AliTOFdigit*)tofDigits->UncheckedAt(i);
+    detind[0] = digit->GetSector();
+    detind[1] = digit->GetPlate();
+    detind[2] = digit->GetStrip();
+    detind[3] = digit->GetPadz();
+    detind[4] = digit->GetPadx();
+
+    Int_t indexLTM[2] = {-1,-1};
+    GetLTMIndex(detind,indexLTM);
+
+    if(fTOFTrigMask->IsON(indexLTM[0],indexLTM[1])) fTOFTrigMap->SetON(indexLTM[0],indexLTM[1]);
+  }
+
+}
 //-----------------------------------------------------------------------------
 void AliTOFTrigger::GetLTMIndex(const Int_t * const detind, Int_t *indexLTM) {
   //
@@ -644,7 +795,7 @@ void AliTOFTrigger::GetLTMIndex(const Int_t * const detind, Int_t *indexLTM) {
       indexLTM[1] = detind[2]+19*2;
     }
     else{
-      AliError("Smth Wrong!!!");
+      //      AliError("Smth Wrong!!!");
     }
   }
   else {
@@ -658,7 +809,7 @@ void AliTOFTrigger::GetLTMIndex(const Int_t * const detind, Int_t *indexLTM) {
       indexLTM[1] = detind[2]+26;
     }
     else{
-      AliError("Smth Wrong!!!");
+      //      AliError("Smth Wrong!!!");
     }
   }
 
@@ -942,7 +1093,7 @@ Bool_t AliTOFTrigger::GetBit(Int_t nDDL, Int_t nTRM, Int_t iChain,
   if (nDDL>=36)
     iLTMindex++;
   iChannelindex=iCH+iTDC*AliTOFGeometry::NCh()-12*AliTOFGeometry::NCh();
-  Int_t index[2]={iLTMindex,iChannelindex};
+  Int_t index[2]={static_cast<Int_t>(iLTMindex),static_cast<Int_t>(iChannelindex)};
   return (index[0]<36)?fCTTMmatrixFront[index[0]][index[1]]:fCTTMmatrixBack[index[0]-36][index[1]];
 
 }
@@ -953,6 +1104,9 @@ void AliTOFTrigger::CreateCTTMMatrix() {
   //
   // Create CTTM bit map
   //
+
+  LoadActiveMask();
+
     Int_t fromTriggertoDCS[72] = {0,1,4,5,8,9,12,13,16,17,20,21,24,25,28,29,32,33,36,37,40,41,44,45,48,49,52,53,56,57,60,61,64,65,68,69,3,
                                  2,7,6,11,10,15,14,19,18,23,22,27,26,31,30,35,34,39,38,43,42,47,46,51,50,55,54,59,58,63,62,67,66,71,70};