]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSTrigger.cxx
- use mass/z for Light Nuclei in all TPC response functions
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrigger.cxx
index 01311810a1d9c77599656cc3defa679a7931a947..f63ede68440c3912186eaadb2bb3dad495f8fdf8 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 /* $Id$ */
-/* $Log $ */
 
 //_________________________________________________________________________  
 //  Class for trigger analysis.
 //  Digits are grouped in TRU's (Trigger Units). A TRU consist of 16x28 
 //  crystals ordered fNTRUPhi x fNTRUZ. The algorithm searches all possible 
-//  2x2 and nxn (n multiple of 4) crystal combinations per each TRU, adding the 
-//  digits amplitude and  finding the maximum. Iti is found is maximum is isolated.
+//  2x2 and nxn (n multiple of 2) crystal combinations per each TRU, adding the 
+//  digits amplitude and  finding the maximum. If found, look if it is isolated.
 //  Maxima are transformed in ADC time samples. Each time bin is compared to the trigger 
 //  threshold until it is larger and then, triggers are set. Thresholds need to be fixed. 
 //  Usage:
 //
 //  //Inside the event loop
-//  AliEMCALTrigger *tr = new AliEMCALTrigger();//Init Trigger
+//  AliPHOSTrigger *tr = new AliPHOSTrigger();//Init Trigger
 //  tr->SetL0Threshold(100);
 //  tr->SetL1JetLowPtThreshold(1000);
+//  tr->SetL1JetMediumPtThreshold(10000);
 //  tr->SetL1JetHighPtThreshold(20000);
 //  ....
 //  tr->Trigger(); //Execute Trigger
 
 
 // --- ROOT system ---
-//#include "TMatrixD.h"
+#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"
-//#include "AliLog.h"
+
 
 ClassImp(AliPHOSTrigger)
 
@@ -60,7 +62,9 @@ AliPHOSTrigger::AliPHOSTrigger()
     fnxnMaxAmp(-1), fnxnCrystalPhi(-1),  fnxnCrystalEta(-1), fnxnSM(0),
     fADCValuesHighnxn(0), fADCValuesLownxn(0),
     fADCValuesHigh2x2(0), fADCValuesLow2x2(0), fDigitsList(0),
-    fL0Threshold(50), fL1JetLowPtThreshold(200), fL1JetHighPtThreshold(500),
+    fAmptrus(0), fAmpmods(0), fTimeRtrus(0),
+    fL0Threshold(50), fL1JetLowPtThreshold(200),   fL1JetMediumPtThreshold(500),  
+    fL1JetHighPtThreshold(1000),
     fNTRU(8), fNTRUZ(2), fNTRUPhi(4), 
     fNCrystalsPhi(16),
     fNCrystalsZ(28),
@@ -79,7 +83,9 @@ AliPHOSTrigger::AliPHOSTrigger()
   SetName("PHOS");
   CreateInputs();
   
-  //Print("") ; 
+  fAmptrus   = new TClonesArray("TMatrixD",1000);
+  fAmpmods   = new TClonesArray("TMatrixD",1000);
+  fTimeRtrus = new TClonesArray("TMatrixD",1000);
 }
 
 //____________________________________________________________________________
@@ -98,8 +104,10 @@ AliPHOSTrigger::AliPHOSTrigger(const AliPHOSTrigger & trig) :
   fADCValuesHigh2x2(trig.fADCValuesHigh2x2),
   fADCValuesLow2x2(trig.fADCValuesLow2x2),
   fDigitsList(trig.fDigitsList),
+  fAmptrus(trig.fAmptrus), fAmpmods(trig.fAmpmods), fTimeRtrus(trig.fTimeRtrus),
   fL0Threshold(trig.fL0Threshold),
   fL1JetLowPtThreshold(trig.fL1JetLowPtThreshold),
+  fL1JetMediumPtThreshold(trig.fL1JetMediumPtThreshold), 
   fL1JetHighPtThreshold(trig.fL1JetHighPtThreshold),
   fNTRU(trig.fNTRU),
   fNTRUZ(trig.fNTRUZ),
@@ -114,11 +122,27 @@ AliPHOSTrigger::AliPHOSTrigger(const AliPHOSTrigger & trig) :
   fnxnAmpOutOfPatchThres(trig.fnxnAmpOutOfPatchThres), 
   fIs2x2Isol(trig.fIs2x2Isol),
   fIsnxnIsol(trig.fIsnxnIsol),  
-  fSimulation(trig.fSimulation), fIsolateInModule(trig.fIsolateInModule)
+  fSimulation(trig.fSimulation), 
+  fIsolateInModule(trig.fIsolateInModule)
 {
   // 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...
+  if(fAmptrus)   { fAmptrus->Delete()  ; delete fAmptrus  ; }
+  if(fAmpmods)   { fAmpmods->Delete()  ; delete fAmpmods  ; }
+  if(fTimeRtrus) { fTimeRtrus->Delete(); delete fTimeRtrus; }
+}
+
 //_________________________________________________________________________
 AliPHOSTrigger & AliPHOSTrigger::operator = (const AliPHOSTrigger &)
 {
@@ -132,20 +156,23 @@ 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_JetLPt_L1","PHOS Jet Low Pt L1", 0x08 ) );
+   fInputs.AddLast( new AliTriggerInput( "0PH0",       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 ) );
  
 }
 
 //____________________________________________________________________________
-void AliPHOSTrigger::FillTRU(const TClonesArray * digits, const AliPHOSGeometry * geom, TClonesArray * ampmatrixtru, TClonesArray * ampmatrixmod, TClonesArray * timeRmatrixtru) const {
+void AliPHOSTrigger::FillTRU(const TClonesArray * digits, const AliPHOSGeometry * geom) const {
 
   //Orders digits ampitudes list and times in fNTRU TRUs (28x16 crystals) 
   //per module. Each TRU is a TMatrixD, and they are kept in TClonesArrays. 
   //In a module, the number of TRU in phi is fNTRUPhi, and the number of 
-  //TRU in eta is fNTRUZ. 
+  //TRU in eta is fNTRUZ. Also fill a matrix with all amplitudes in module for isolation studies. 
 
   //Check data members
   
@@ -161,16 +188,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((*fAmptrus)[k])   TMatrixD(amptrus) ;
+    new((*fTimeRtrus)[k]) TMatrixD(timeRtrus) ; 
   }
 
   //List of Modules matrices initialized to 0.
@@ -178,19 +205,18 @@ 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((*fAmpmods)[k])   TMatrixD(ampmods) ;
   }
   
   AliPHOSDigit * dig ;
  
   //Digits loop to fill TRU matrices with amplitudes.
-
   for(Int_t idig = 0 ; idig < digits->GetEntriesFast() ; idig++){
     
     dig    = static_cast<AliPHOSDigit *>(digits->At(idig)) ;
@@ -220,8 +246,8 @@ void AliPHOSTrigger::FillTRU(const TClonesArray * digits, const AliPHOSGeometry
       Int_t itru  = (row-1) + (col-1)*fNTRUPhi + (relid[0]-1)*fNTRU ;
 
       //Fill TRU matrix with crystal values
-      TMatrixD * amptrus   = dynamic_cast<TMatrixD *>(ampmatrixtru->At(itru)) ;
-      TMatrixD * timeRtrus = dynamic_cast<TMatrixD *>(timeRmatrixtru->At(itru)) ;
+      TMatrixD * amptrus   = static_cast<TMatrixD *>(fAmptrus  ->At(itru)) ;
+      TMatrixD * timeRtrus = static_cast<TMatrixD *>(fTimeRtrus->At(itru)) ;
 
       //Calculate row and column of the crystal inside the TRU with number itru
       Int_t irow = (relid[2]-1) - (row-1) *  fNCrystalsPhi;    
@@ -230,15 +256,15 @@ void AliPHOSTrigger::FillTRU(const TClonesArray * digits, const AliPHOSGeometry
       (*amptrus)(irow,icol)   = amp ;
       (*timeRtrus)(irow,icol) = timeR ;
 
-      //####################MODULE##################
-      TMatrixD * ampmods   = dynamic_cast<TMatrixD *>(ampmatrixmod->At(relid[0]-1)) ;
+      //####################MODULE MATRIX ##################
+      TMatrixD * ampmods   = static_cast<TMatrixD *>(fAmpmods->At(relid[0]-1)) ;
       (*ampmods)(relid[2]-1,relid[3]-1)   = amp ;
     }
   }
 }
 
 //______________________________________________________________________
-void AliPHOSTrigger::GetCrystalPhiEtaIndexInModuleFromTRUIndex(const Int_t itru,const Int_t iphitru,const Int_t ietatru,Int_t &iphiMod,Int_t &ietaMod) const 
+void AliPHOSTrigger::GetCrystalPhiEtaIndexInModuleFromTRUIndex(Int_t itru, Int_t iphitru, Int_t ietatru,Int_t &iphiMod,Int_t &ietaMod) const 
 {
   // This method transforms the (eta,phi) index of a crystals in a 
   // TRU matrix into Super Module (eta,phi) index.
@@ -251,12 +277,12 @@ void AliPHOSTrigger::GetCrystalPhiEtaIndexInModuleFromTRUIndex(const Int_t itru,
   //Calculate the (eta,phi) index in SM
   
   iphiMod = fNCrystalsPhi*(row-1) + iphitru + 1 ;
-  ietaMod = fNCrystalsZ*(col-1) + ietatru + 1 ;
+  ietaMod = fNCrystalsZ*(col-1)   + ietatru + 1 ;
 
 }
 
 //____________________________________________________________________________
-Bool_t AliPHOSTrigger::IsPatchIsolated(Int_t iPatchType, const TClonesArray * ampmatrixes, const Int_t imod, const Int_t mtru, const Float_t maxamp, const Int_t maxphi, const Int_t maxeta) {
+Bool_t AliPHOSTrigger::IsPatchIsolated(Int_t iPatchType, const Int_t imod, const Int_t mtru, const Float_t maxamp, const Int_t maxphi, const Int_t maxeta) {
 
   //Calculate if the maximum patch found is isolated, find amplitude around maximum (2x2 or nxn) patch, 
   //inside isolation patch . iPatchType = 0 means calculation for 2x2 patch, 
@@ -279,19 +305,18 @@ Bool_t AliPHOSTrigger::IsPatchIsolated(Int_t iPatchType, const TClonesArray * am
   Int_t rowborder = 0;
 
   if(fIsolateInModule){
-    ampmatrix = dynamic_cast<TMatrixD *>(ampmatrixes->At(imod)) ;
+    ampmatrix = static_cast<TMatrixD *>(fAmpmods->At(imod)) ;
     rowborder = fNCrystalsPhi*fNTRUPhi;
     colborder = fNCrystalsZ*fNTRUZ;
     AliDebug(2,"Isolate trigger in Module");
   }
   else{
-    ampmatrix = dynamic_cast<TMatrixD *>(ampmatrixes->At(itru)) ;
+    ampmatrix = static_cast<TMatrixD *>(fAmptrus->At(itru)) ;
     rowborder = fNCrystalsPhi;
     colborder = fNCrystalsZ;
     AliDebug(2,"Isolate trigger in TRU");
   }
 
-
   //Define patch cells
   Int_t isolcells = fIsolPatchSize*(1+iPatchType);
   Int_t ipatchcells = 2*(1+fPatchSize*iPatchType);
@@ -304,7 +329,7 @@ Bool_t AliPHOSTrigger::IsPatchIsolated(Int_t iPatchType, const TClonesArray * am
   AliDebug(2,Form("Patch: minrow %d, maxrow %d, mincol %d, maxcol %d",minrow,maxrow,mincol,maxcol));
   
   if(minrow < 0 || mincol < 0 || maxrow > rowborder || maxcol > colborder){
-    AliDebug(1,Form("Out of Module range, cannot isolate patch"));
+    AliDebug(1,Form("Out of Module/TRU range, cannot isolate patch"));
     return kFALSE;
   }
 
@@ -342,7 +367,8 @@ 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 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. 
@@ -352,22 +378,22 @@ 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++){
-    TMatrixD * amptru   = dynamic_cast<TMatrixD *>(amptrus->At(itru)) ;
-    TMatrixD * timeRtru = dynamic_cast<TMatrixD *>(timeRtrus->At(itru)) ;
+    TMatrixD * amptru   = static_cast<TMatrixD *>(fAmptrus  ->At(itru)) ;
+    TMatrixD * timeRtru = static_cast<TMatrixD *>(fTimeRtrus->At(itru)) ;
     Int_t mtru = itru-imod*fNTRU ; //Number of TRU in Module
     
     //Sliding 2x2, add 2x2 amplitudes (NOT OVERLAP)
@@ -376,25 +402,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);
        }
       }
     }
@@ -407,37 +433,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);
       }
   }
 }
@@ -463,7 +489,7 @@ void AliPHOSTrigger::Print(const Option_t * opt) const
     printf( "             Patch Size, n x n: %d x %d cells\n",2*(fPatchSize+1), 2*(fPatchSize+1));
     printf( "               -nxn crystals sum (overlapped)    : %10.2f, in Super Module %d\n",
            fnxnMaxAmp,fnxnSM) ; 
-    printf( "               -nxn from row %d to row %d and from column %d to column %d\n", fnxnCrystalPhi, fnxnCrystalPhi+4, fnxnCrystalEta, fnxnCrystalEta+4) ; 
+    printf( "               -nxn from row %d to row %d and from column %d to column %d\n", fnxnCrystalPhi, fnxnCrystalPhi+4*fPatchSize, fnxnCrystalEta, fnxnCrystalEta+4*fPatchSize) ; 
     printf( "               -nxn Isolation Patch %d x %d, Amplitude out of nxn patch is %f, threshold %f, Isolated? %d \n", 
            4*fIsolPatchSize+2*(fPatchSize+1),4*fIsolPatchSize+2*(fPatchSize+1) ,  fnxnAmpOutOfPatch,  fnxnAmpOutOfPatchThres,static_cast<Int_t> (fIsnxnIsol) ) ; 
   }
@@ -475,7 +501,7 @@ void AliPHOSTrigger::Print(const Option_t * opt) const
          fL0Threshold) ;  
   
   printf( "             Threshold for LO %10.2f\n", fL0Threshold) ;  
-  in = (AliTriggerInput*)fInputs.FindObject( "PHOS_L0" );
+  in = (AliTriggerInput*)fInputs.FindObject( "0PH0" );
   if(in->GetValue())
     printf( "             *** PHOS LO is set ***\n") ; 
   
@@ -484,15 +510,20 @@ void AliPHOSTrigger::Print(const Option_t * opt) const
   if(in->GetValue())
     printf( "             *** PHOS Jet Low Pt for L1 is set ***\n") ;
   
+  printf( "             Jet Medium Pt Threshold for L1 %10.2f\n", fL1JetMediumPtThreshold) ;
+  in = (AliTriggerInput*)fInputs.FindObject( "PHOS_JetMPt_L1" );
+  if(in->GetValue())
+    printf( "             *** PHOS Jet Medium Pt for L1 is set ***\n") ;
+  
   printf( "             Jet High Pt Threshold for L1 %10.2f\n", fL1JetHighPtThreshold) ;  
   in = (AliTriggerInput*) fInputs.FindObject( "PHOS_JetHPt_L1" );
   if(in->GetValue())
     printf( "              *** PHOS Jet High Pt for L1 is set ***\n") ;
+  
 }
 
 //____________________________________________________________________________
-void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMod, const TMatrixD * ampmax2, const TMatrixD * ampmaxn)  
+void AliPHOSTrigger::SetTriggers(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.
@@ -507,18 +538,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
     }
   }
@@ -527,8 +558,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 ){
@@ -542,24 +573,27 @@ void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMo
     
     //Isolated patch?
     if(fIsolateInModule)
-      fIs2x2Isol =  IsPatchIsolated(0, ampmatrix, iMod, mtru2,  f2x2MaxAmp, f2x2CrystalPhi,f2x2CrystalEta) ;
+      fIs2x2Isol =  IsPatchIsolated(0, iMod, mtru2,  f2x2MaxAmp, f2x2CrystalPhi,f2x2CrystalEta) ;
     else
-      fIs2x2Isol =  IsPatchIsolated(0, ampmatrix, iMod, mtru2,  f2x2MaxAmp,  static_cast<Int_t>(max2[1]), static_cast<Int_t>(max2[2])) ;
+      fIs2x2Isol =  IsPatchIsolated(0, 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
     for(Int_t i = 0 ; i < nTimeBins ; i++){
       if(fADCValuesHigh2x2[i] >= fL0Threshold || fADCValuesLow2x2[i] >= fL0Threshold) {
-       SetInput("PHOS_L0") ;
+       SetInput("0PH0") ;
        break;
       }
     }
@@ -577,18 +611,20 @@ void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMo
     
     //Isolated patch?
     if(fIsolateInModule)
-      fIsnxnIsol =  IsPatchIsolated(1, ampmatrix, iMod, mtrun,  fnxnMaxAmp, fnxnCrystalPhi, fnxnCrystalEta) ;
+      fIsnxnIsol =  IsPatchIsolated(1, iMod, mtrun,  fnxnMaxAmp, fnxnCrystalPhi, fnxnCrystalEta) ;
     else
-      fIsnxnIsol =  IsPatchIsolated(1, ampmatrix, iMod, mtrun,  fnxnMaxAmp,  static_cast<Int_t>(maxn[1]), static_cast<Int_t>(maxn[2])) ;
+      fIsnxnIsol =  IsPatchIsolated(1, 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
@@ -598,6 +634,13 @@ void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMo
        break; 
       }
     }
+    //SetL1 Medium
+    for(Int_t i = 0 ; i < nTimeBins ; i++){
+      if(fADCValuesHighnxn[i] >= fL1JetMediumPtThreshold  || fADCValuesLownxn[i] >= fL1JetMediumPtThreshold){
+       SetInput("PHOS_JetMPt_L1") ;
+       break; 
+      }
+    }
     //SetL1 High
     for(Int_t i = 0 ; i < nTimeBins ; i++){
       if(fADCValuesHighnxn[i] >= fL1JetHighPtThreshold || fADCValuesLownxn[i] >= fL1JetHighPtThreshold){
@@ -609,17 +652,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::Instance() ;
+  AliPHOSLoader * phosLoader = static_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();
@@ -632,34 +684,37 @@ void AliPHOSTrigger::Trigger()
 
   //Take the digits list if simulation
   if(fSimulation)
-    fDigitsList = gime->Digits() ;
+    fDigitsList = phosLoader->Digits() ;
   
   if(!fDigitsList)
     AliFatal("Digits not found !") ;
   
   //Fill TRU Matrix  
-  TClonesArray * amptrus   = new TClonesArray("TMatrixD",1000);
-  TClonesArray * ampmods   = new TClonesArray("TMatrixD",1000);
-  TClonesArray * timeRtrus = new TClonesArray("TMatrixD",1000);
-  FillTRU(fDigitsList,geom,amptrus, ampmods,timeRtrus) ;
+//   TClonesArray * amptrus   = new TClonesArray("TMatrixD",1000);
+//   TClonesArray * ampmods   = new TClonesArray("TMatrixD",1000);
+//   TClonesArray * timeRtrus = new TClonesArray("TMatrixD",1000);
+  FillTRU(fDigitsList,geom) ;
 
   //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++) {
 
     //Do 2x2 and nxn sums, select maximums. 
-    MakeSlidingCell(amptrus, timeRtrus, imod, ampmax2, ampmaxn);
+    MakeSlidingCell(imod, ampmax2, ampmaxn);
     //Set the trigger
-    if(fIsolateInModule)
-      SetTriggers(ampmods,imod,ampmax2,ampmaxn) ;
-    if(!fIsolateInModule)
-      SetTriggers(amptrus,imod,ampmax2,ampmaxn) ;
+    SetTriggers(imod,ampmax2,ampmaxn) ;
   }
 
+  fAmptrus->Delete();
+//   delete amptrus; amptrus=0;
+  fAmpmods->Delete();
+//   delete ampmods; ampmods=0;
+  fTimeRtrus->Delete();
+//   delete timeRtrus; timeRtrus=0;
   //Print();
 
 }