]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSTrigger.cxx
Macro for checking the serial & bin number of the mounted manus
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrigger.cxx
index 91b45e62abe01991a2832a2e8a5b5aacebd0c174..ba2bbc4fb58d66ce34c8e150a223105e8a8f2815 100644 (file)
 
 
 // --- ROOT system ---
+#include "TMath.h"
 
 // --- ALIROOT system ---
+#include "AliConfig.h"
 #include "AliPHOS.h"
 #include "AliPHOSTrigger.h" 
 #include "AliPHOSGeometry.h"
-#include "AliPHOSGetter.h" 
+#include "AliPHOSDigit.h" 
+#include "AliPHOSLoader.h" 
 #include "AliPHOSPulseGenerator.h" 
 #include "AliTriggerInput.h"
 
@@ -121,6 +124,18 @@ AliPHOSTrigger::AliPHOSTrigger(const AliPHOSTrigger & trig) :
   // cpy ctor
 }
 
+//_________________________________________________________________________
+AliPHOSTrigger::~AliPHOSTrigger() 
+{
+  // dtor
+  
+  if(fADCValuesHighnxn)delete [] fADCValuesHighnxn;
+  if(fADCValuesLownxn)delete [] fADCValuesLownxn;
+  if(fADCValuesHigh2x2)delete []  fADCValuesHigh2x2;
+  if(fADCValuesLow2x2)delete [] fADCValuesLow2x2;
+  // fDigitsList is now ours...
+}
+
 //_________________________________________________________________________
 AliPHOSTrigger & AliPHOSTrigger::operator = (const AliPHOSTrigger &)
 {
@@ -134,11 +149,13 @@ void AliPHOSTrigger::CreateInputs()
    
    // Do not create inputs again!!
    if( fInputs.GetEntriesFast() > 0 ) return;
+
+   TString name = GetName();
    
-   fInputs.AddLast( new AliTriggerInput( "PHOS_L0",       "PHOS L0", 0x02 ) );
-   fInputs.AddLast( new AliTriggerInput( "PHOS_JetHPt_L1","PHOS Jet High Pt L1", 0x04 ) );
-   fInputs.AddLast( new AliTriggerInput( "PHOS_JetMPt_L1","PHOS Jet Medium Pt L1", 0x08 ) );
-   fInputs.AddLast( new AliTriggerInput( "PHOS_JetLPt_L1","PHOS Jet Low Pt L1", 0x016 ) );
+   fInputs.AddLast( new AliTriggerInput( "PHOS_L0",       name, 0 ) );
+   fInputs.AddLast( new AliTriggerInput( "PHOS_JetHPt_L1",name, 1 ) );
+   fInputs.AddLast( new AliTriggerInput( "PHOS_JetMPt_L1",name, 1 ) );
+   fInputs.AddLast( new AliTriggerInput( "PHOS_JetLPt_L1",name, 1 ) );
  
 }
 
@@ -164,16 +181,16 @@ void AliPHOSTrigger::FillTRU(const TClonesArray * digits, const AliPHOSGeometry
 
   //List of TRU matrices initialized to 0.
   for(Int_t k = 0; k < fNTRU*nModules ; k++){
-    TMatrixD  * amptrus   = new TMatrixD(fNCrystalsPhi,fNCrystalsZ) ;
-    TMatrixD  * timeRtrus = new TMatrixD(fNCrystalsPhi,fNCrystalsZ) ;
+    TMatrixD   amptrus(fNCrystalsPhi,fNCrystalsZ) ;
+    TMatrixD   timeRtrus(fNCrystalsPhi,fNCrystalsZ) ;
     for(Int_t i = 0; i < fNCrystalsPhi; i++){
       for(Int_t j = 0; j < fNCrystalsZ; j++){
-       (*amptrus)(i,j)   = 0.0;
-       (*timeRtrus)(i,j) = 0.0;
+       amptrus(i,j)   = 0.0;
+       timeRtrus(i,j) = 0.0;
       }
     }
-    new((*ampmatrixtru)[k])   TMatrixD(*amptrus) ;
-    new((*timeRmatrixtru)[k]) TMatrixD(*timeRtrus) ; 
+    new((*ampmatrixtru)[k])   TMatrixD(amptrus) ;
+    new((*timeRmatrixtru)[k]) TMatrixD(timeRtrus) ; 
   }
 
   //List of Modules matrices initialized to 0.
@@ -181,13 +198,13 @@ void AliPHOSTrigger::FillTRU(const TClonesArray * digits, const AliPHOSGeometry
   Int_t nmodz = geom->GetNZ();
   
   for(Int_t k = 0; k < nModules ; k++){
-    TMatrixD  * ampmods   = new TMatrixD(nmodphi,nmodz) ;
+    TMatrixD  ampmods(nmodphi,nmodz) ;
     for(Int_t i = 0; i < nmodphi; i++){
       for(Int_t j = 0; j < nmodz; j++){
-       (*ampmods)(i,j)   = 0.0;
+       ampmods(i,j)   = 0.0;
       }
     }
-    new((*ampmatrixmod)[k])   TMatrixD(*ampmods) ;
+    new((*ampmatrixmod)[k])   TMatrixD(ampmods) ;
   }
   
   AliPHOSDigit * dig ;
@@ -316,7 +333,7 @@ Bool_t AliPHOSTrigger::IsPatchIsolated(Int_t iPatchType, const TClonesArray * am
 
   AliDebug(2,Form("Type %d, Maximum amplitude %f, patch+isol square %f",iPatchType, maxamp, amp));
 
-  if(amp < maxamp){
+  if(TMath::Nint(amp*1E5) < TMath::Nint(maxamp*1E5)){
     AliError(Form("Bad sum: Type %d, Maximum amplitude %f, patch+isol square %f",iPatchType, maxamp, amp));
     return kFALSE;
   }
@@ -343,7 +360,7 @@ Bool_t AliPHOSTrigger::IsPatchIsolated(Int_t iPatchType, const TClonesArray * am
 
 
 //____________________________________________________________________________
-void AliPHOSTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClonesArray * timeRtrus, const Int_t imod, TMatrixD *ampmax2, TMatrixD *ampmaxn){
+void AliPHOSTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClonesArray * timeRtrus, const Int_t imod, TMatrixD &ampmax2, TMatrixD &ampmaxn){
   //Sums energy of all possible 2x2 (L0) and nxn (L1) crystals per each TRU. 
   //Fast signal in the experiment is given by 2x2 crystals, 
   //for this reason we loop inside the TRU crystals by 2. 
@@ -353,17 +370,17 @@ void AliPHOSTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClones
   Float_t ampn = 0 ; 
   for(Int_t i = 0; i < 4; i++){
     for(Int_t j = 0; j < fNTRU; j++){
-      (*ampmax2)(i,j) = -1;
-      (*ampmaxn)(i,j) = -1;
+      ampmax2(i,j) = -1;
+      ampmaxn(i,j) = -1;
     }
   }
 
   //Create matrix that will contain 2x2 amplitude sums
   //used to calculate the nxn sums
-  TMatrixD  * tru2x2 = new TMatrixD(fNCrystalsPhi/2,fNCrystalsZ/2) ;
+  TMatrixD  tru2x2(fNCrystalsPhi/2,fNCrystalsZ/2) ;
   for(Int_t i = 0; i < fNCrystalsPhi/2; i++)
     for(Int_t j = 0; j < fNCrystalsZ/2; j++)
-      (*tru2x2)(i,j) = -1.;
+      tru2x2(i,j) = -1.;
     
   //Loop over all TRUS in a module
   for(Int_t itru = 0 + imod  * fNTRU ; itru < (imod+1)*fNTRU ; itru++){
@@ -377,25 +394,25 @@ void AliPHOSTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClones
        amp2 = (*amptru)(irow,icol)+(*amptru)(irow+1,icol)+
          (*amptru)(irow,icol+1)+(*amptru)(irow+1,icol+1);
        //Fill new matrix with added 2x2 crystals for use in nxn sums
-       (*tru2x2)(irow/2,icol/2) = amp2 ;
+       tru2x2(irow/2,icol/2) = amp2 ;
        //Select 2x2 maximum sums to select L0 
-       if(amp2 > (*ampmax2)(0,mtru)){
-         (*ampmax2)(0,mtru) = amp2 ; 
-         (*ampmax2)(1,mtru) = irow;
-         (*ampmax2)(2,mtru) = icol;
+       if(amp2 > ampmax2(0,mtru)){
+         ampmax2(0,mtru) = amp2 ; 
+         ampmax2(1,mtru) = irow;
+         ampmax2(2,mtru) = icol;
        }
       }
     }
 
     //Find most recent time in the selected 2x2 cell
-    (*ampmax2)(3,mtru) = 1 ;
-    Int_t row2 =  static_cast <Int_t> ((*ampmax2)(1,mtru));
-    Int_t col2 =  static_cast <Int_t> ((*ampmax2)(2,mtru));
+    ampmax2(3,mtru) = 1 ;
+    Int_t row2 =  static_cast <Int_t> (ampmax2(1,mtru));
+    Int_t col2 =  static_cast <Int_t> (ampmax2(2,mtru));
     for(Int_t i = 0; i<2; i++){
       for(Int_t j = 0; j<2; j++){
        if((*amptru)(row2+i,col2+j) > 0 &&  (*timeRtru)(row2+i,col2+j)> 0){       
-         if((*timeRtru)(row2+i,col2+j) <  (*ampmax2)(3,mtru)  )
-           (*ampmax2)(3,mtru) =  (*timeRtru)(row2+i,col2+j);
+         if((*timeRtru)(row2+i,col2+j) <  ampmax2(3,mtru)  )
+           ampmax2(3,mtru) =  (*timeRtru)(row2+i,col2+j);
        }
       }
     }
@@ -408,37 +425,37 @@ void AliPHOSTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClones
          if( (irow+fPatchSize) < fNCrystalsPhi/2 && (icol+fPatchSize) < fNCrystalsZ/2){//Avoid exit the TRU
            for(Int_t i = 0 ; i <= fPatchSize ; i++)
              for(Int_t j = 0 ; j <= fPatchSize ; j++)
-               ampn += (*tru2x2)(irow+i,icol+j);
+               ampn += tru2x2(irow+i,icol+j);
            //Select nxn maximum sums to select L1 
-           if(ampn > (*ampmaxn)(0,mtru)){
-             (*ampmaxn)(0,mtru) = ampn ; 
-             (*ampmaxn)(1,mtru) = irow*2;
-             (*ampmaxn)(2,mtru) = icol*2;
+           if(ampn > ampmaxn(0,mtru)){
+             ampmaxn(0,mtru) = ampn ; 
+             ampmaxn(1,mtru) = irow*2;
+             ampmaxn(2,mtru) = icol*2;
            }
          }
        }
       }
       
       //Find most recent time in selected nxn cell
-      (*ampmaxn)(3,mtru) = 1 ;
-      Int_t rown =  static_cast <Int_t> ((*ampmaxn)(1,mtru));
-      Int_t coln =  static_cast <Int_t> ((*ampmaxn)(2,mtru));
+      ampmaxn(3,mtru) = 1 ;
+      Int_t rown =  static_cast <Int_t> (ampmaxn(1,mtru));
+      Int_t coln =  static_cast <Int_t> (ampmaxn(2,mtru));
       for(Int_t i = 0; i<4*fPatchSize; i++){
        for(Int_t j = 0; j<4*fPatchSize; j++){
          if( (rown+i) < fNCrystalsPhi && (coln+j) < fNCrystalsZ/2){//Avoid exit the TRU
            if((*amptru)(rown+i,coln+j) > 0 &&  (*timeRtru)(rown+i,coln+j)> 0){
-             if((*timeRtru)(rown+i,coln+j) <  (*ampmaxn)(3,mtru)  )
-               (*ampmaxn)(3,mtru) =  (*timeRtru)(rown+i,coln+j);
+             if((*timeRtru)(rown+i,coln+j) <  ampmaxn(3,mtru)  )
+               ampmaxn(3,mtru) =  (*timeRtru)(rown+i,coln+j);
            }
          }
        }
       }
     }
     else {  
-       (*ampmaxn)(0,mtru) =  (*ampmax2)(0,mtru); 
-       (*ampmaxn)(1,mtru) =  (*ampmax2)(1,mtru);
-       (*ampmaxn)(2,mtru) =  (*ampmax2)(2,mtru);
-       (*ampmaxn)(3,mtru) =  (*ampmax2)(3,mtru);
+       ampmaxn(0,mtru) =  ampmax2(0,mtru); 
+       ampmaxn(1,mtru) =  ampmax2(1,mtru);
+       ampmaxn(2,mtru) =  ampmax2(2,mtru);
+       ampmaxn(3,mtru) =  ampmax2(3,mtru);
       }
   }
 }
@@ -498,7 +515,7 @@ void AliPHOSTrigger::Print(const Option_t * opt) const
 }
 
 //____________________________________________________________________________
-void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMod, const TMatrixD * ampmax2, const TMatrixD * ampmaxn)  
+void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMod, const TMatrixD & ampmax2, const TMatrixD & ampmaxn)  
 {
   //Checks the 2x2 and nxn maximum amplitude per each TRU and compares 
   //with the different L0 and L1 triggers thresholds. It finds if maximum amplitudes are isolated.
@@ -513,18 +530,18 @@ void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMo
   //Find maximum summed amplitude of all the TRU 
   //in a Module
   for(Int_t i = 0 ; i < fNTRU ; i++){
-    if(max2[0] < (*ampmax2)(0,i) ){
-      max2[0] =  (*ampmax2)(0,i) ; // 2x2 summed max amplitude
-      max2[1] =  (*ampmax2)(1,i) ; // corresponding phi position in TRU
-      max2[2] =  (*ampmax2)(2,i) ; // corresponding eta position in TRU
-      max2[3] =  (*ampmax2)(3,i) ; // corresponding most recent time
+    if(max2[0] < ampmax2(0,i) ){
+      max2[0] =  ampmax2(0,i) ; // 2x2 summed max amplitude
+      max2[1] =  ampmax2(1,i) ; // corresponding phi position in TRU
+      max2[2] =  ampmax2(2,i) ; // corresponding eta position in TRU
+      max2[3] =  ampmax2(3,i) ; // corresponding most recent time
       mtru2   = i ; // TRU number in module
     }
-    if(maxn[0] < (*ampmaxn)(0,i) ){
-      maxn[0] =  (*ampmaxn)(0,i) ; // nxn summed max amplitude
-      maxn[1] =  (*ampmaxn)(1,i) ; // corresponding phi position in TRU
-      maxn[2] =  (*ampmaxn)(2,i) ; // corresponding eta position in TRU
-      maxn[3] =  (*ampmaxn)(3,i) ; // corresponding most recent time
+    if(maxn[0] < ampmaxn(0,i) ){
+      maxn[0] =  ampmaxn(0,i) ; // nxn summed max amplitude
+      maxn[1] =  ampmaxn(1,i) ; // corresponding phi position in TRU
+      maxn[2] =  ampmaxn(2,i) ; // corresponding eta position in TRU
+      maxn[3] =  ampmaxn(3,i) ; // corresponding most recent time
       mtrun   = i ; // TRU number in module
     }
   }
@@ -533,8 +550,8 @@ void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMo
   Float_t maxtimeR2 = -1 ;
   Float_t maxtimeRn = -1 ;
   // Create a shaper pulse object
-  AliPHOSPulseGenerator *pulse = new AliPHOSPulseGenerator();
-  Int_t nTimeBins = pulse->GetRawFormatTimeBins() ;
+  AliPHOSPulseGenerator pulse ;
+  Int_t nTimeBins = pulse.GetRawFormatTimeBins() ;
  
   //Set max 2x2 amplitude and select L0 trigger
   if(max2[0] > f2x2MaxAmp ){
@@ -553,13 +570,16 @@ void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMo
       fIs2x2Isol =  IsPatchIsolated(0, ampmatrix, iMod, mtru2,  f2x2MaxAmp,  static_cast<Int_t>(max2[1]), static_cast<Int_t>(max2[2])) ;
 
     //Transform digit amplitude in Raw Samples
-    fADCValuesLow2x2  = new Int_t[nTimeBins];
-    fADCValuesHigh2x2 = new Int_t[nTimeBins];
+    if (fADCValuesLow2x2 == 0) {
+      fADCValuesLow2x2  = new Int_t[nTimeBins];
+    }
+    if(!fADCValuesHigh2x2) fADCValuesHigh2x2 = new Int_t[nTimeBins];
+
     
-    pulse->SetAmplitude(f2x2MaxAmp);
-    pulse->SetTZero(maxtimeR2);
-    pulse->MakeSamples();
-    pulse->GetSamples(fADCValuesHigh2x2, fADCValuesLow2x2) ; 
+    pulse.SetAmplitude(f2x2MaxAmp);
+    pulse.SetTZero(maxtimeR2);
+    pulse.MakeSamples();
+    pulse.GetSamples(fADCValuesHigh2x2, fADCValuesLow2x2) ; 
     
     //Set Trigger Inputs, compare ADC time bins until threshold is attained
     //Set L0
@@ -588,13 +608,15 @@ void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMo
       fIsnxnIsol =  IsPatchIsolated(1, ampmatrix, iMod, mtrun,  fnxnMaxAmp,  static_cast<Int_t>(maxn[1]), static_cast<Int_t>(maxn[2])) ;
 
     //Transform digit amplitude in Raw Samples
-    fADCValuesHighnxn = new Int_t[nTimeBins];
-    fADCValuesLownxn  = new Int_t[nTimeBins];
+    if (fADCValuesHighnxn == 0) {
+      fADCValuesHighnxn = new Int_t[nTimeBins];
+      fADCValuesLownxn  = new Int_t[nTimeBins];
+    }
 
-    pulse->SetAmplitude(maxtimeRn);
-    pulse->SetTZero(fnxnMaxAmp);
-    pulse->MakeSamples();
-    pulse->GetSamples(fADCValuesHighnxn, fADCValuesLownxn) ;
+    pulse.SetAmplitude(fnxnMaxAmp);
+    pulse.SetTZero(maxtimeRn);
+    pulse.MakeSamples();
+    pulse.GetSamples(fADCValuesHighnxn, fADCValuesLownxn) ;
     
     //Set Trigger Inputs, compare ADC time bins until threshold is attained
     //SetL1 Low
@@ -622,17 +644,26 @@ void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMo
 }
 
 //____________________________________________________________________________
-void AliPHOSTrigger::Trigger() 
+void AliPHOSTrigger::Trigger(TClonesArray *digits
 {
-
   //Main Method to select triggers.
-  AliRunLoader *rl = gAlice->GetRunLoader();
-  //Getter
-  AliPHOSGetter * gime = AliPHOSGetter::Instance( rl->GetFileName() ) ;
-  //AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
 
-  //Get Geometry
-  const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
+  fDigitsList = digits;
+  DoIt() ; 
+}
+
+//____________________________________________________________________________
+void AliPHOSTrigger::DoIt()
+{
+  // does the trigger job
+
+  AliRunLoader* rl = AliRunLoader::GetRunLoader() ;
+  AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
+  
+  // Get PHOS Geometry object
+  AliPHOSGeometry *geom;
+  if (!(geom = AliPHOSGeometry::GetInstance())) 
+        geom = AliPHOSGeometry::GetInstance("IHEP","");
    
   //Define parameters
   Int_t nModules     = geom->GetNModules();
@@ -645,7 +676,7 @@ void AliPHOSTrigger::Trigger()
 
   //Take the digits list if simulation
   if(fSimulation)
-    fDigitsList = gime->Digits() ;
+    fDigitsList = phosLoader->Digits() ;
   
   if(!fDigitsList)
     AliFatal("Digits not found !") ;
@@ -659,8 +690,8 @@ void AliPHOSTrigger::Trigger()
   //Do Crystal Sliding and select Trigger
   //Initialize varible that will contain maximum amplitudes and 
   //its corresponding cell position in eta and phi, and time.
-  TMatrixD  * ampmax2 = new TMatrixD(4,fNTRU) ;
-  TMatrixD  * ampmaxn = new TMatrixD(4,fNTRU) ;
+  TMatrixD   ampmax2(4,fNTRU) ;
+  TMatrixD   ampmaxn(4,fNTRU) ;
 
   for(Int_t imod = 0 ; imod < nModules ; imod++) {
 
@@ -669,10 +700,16 @@ void AliPHOSTrigger::Trigger()
     //Set the trigger
     if(fIsolateInModule)
       SetTriggers(ampmods,imod,ampmax2,ampmaxn) ;
-    if(!fIsolateInModule)
+    else
       SetTriggers(amptrus,imod,ampmax2,ampmaxn) ;
   }
 
+  amptrus->Delete();
+  delete amptrus; amptrus=0;
+  ampmods->Delete();
+  delete ampmods; ampmods=0;
+  timeRtrus->Delete();
+  delete timeRtrus; timeRtrus=0;
   //Print();
 
 }