]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSTrigger.cxx
Merge branch 'master' into LocalDev
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrigger.cxx
index a9fbcb4433dc3e705bbe1412164c5d43244e9082..f63ede68440c3912186eaadb2bb3dad495f8fdf8 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"
 
@@ -59,6 +62,7 @@ AliPHOSTrigger::AliPHOSTrigger()
     fnxnMaxAmp(-1), fnxnCrystalPhi(-1),  fnxnCrystalEta(-1), fnxnSM(0),
     fADCValuesHighnxn(0), fADCValuesLownxn(0),
     fADCValuesHigh2x2(0), fADCValuesLow2x2(0), fDigitsList(0),
+    fAmptrus(0), fAmpmods(0), fTimeRtrus(0),
     fL0Threshold(50), fL1JetLowPtThreshold(200),   fL1JetMediumPtThreshold(500),  
     fL1JetHighPtThreshold(1000),
     fNTRU(8), fNTRUZ(2), fNTRUPhi(4), 
@@ -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,6 +104,7 @@ 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), 
@@ -121,6 +128,21 @@ 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...
+  if(fAmptrus)   { fAmptrus->Delete()  ; delete fAmptrus  ; }
+  if(fAmpmods)   { fAmpmods->Delete()  ; delete fAmpmods  ; }
+  if(fTimeRtrus) { fTimeRtrus->Delete(); delete fTimeRtrus; }
+}
+
 //_________________________________________________________________________
 AliPHOSTrigger & AliPHOSTrigger::operator = (const AliPHOSTrigger &)
 {
@@ -134,16 +156,18 @@ 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( "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. 
@@ -172,8 +196,8 @@ void AliPHOSTrigger::FillTRU(const TClonesArray * digits, const AliPHOSGeometry
        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.
@@ -187,7 +211,7 @@ void AliPHOSTrigger::FillTRU(const TClonesArray * digits, const AliPHOSGeometry
        ampmods(i,j)   = 0.0;
       }
     }
-    new((*ampmatrixmod)[k])   TMatrixD(ampmods) ;
+    new((*fAmpmods)[k])   TMatrixD(ampmods) ;
   }
   
   AliPHOSDigit * dig ;
@@ -222,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;    
@@ -233,14 +257,14 @@ void AliPHOSTrigger::FillTRU(const TClonesArray * digits, const AliPHOSGeometry
       (*timeRtrus)(irow,icol) = timeR ;
 
       //####################MODULE MATRIX ##################
-      TMatrixD * ampmods   = dynamic_cast<TMatrixD *>(ampmatrixmod->At(relid[0]-1)) ;
+      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.
@@ -258,7 +282,7 @@ void AliPHOSTrigger::GetCrystalPhiEtaIndexInModuleFromTRUIndex(const Int_t itru,
 }
 
 //____________________________________________________________________________
-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, 
@@ -281,13 +305,13 @@ 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");
@@ -343,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. 
@@ -367,8 +392,8 @@ void AliPHOSTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClones
     
   //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)
@@ -476,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") ; 
   
@@ -498,7 +523,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 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.
@@ -548,15 +573,16 @@ 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
     if (fADCValuesLow2x2 == 0) {
       fADCValuesLow2x2  = new Int_t[nTimeBins];
-      fADCValuesHigh2x2 = new Int_t[nTimeBins];
     }
+    if(!fADCValuesHigh2x2) fADCValuesHigh2x2 = new Int_t[nTimeBins];
+
     
     pulse.SetAmplitude(f2x2MaxAmp);
     pulse.SetTZero(maxtimeR2);
@@ -567,7 +593,7 @@ void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMo
     //Set L0
     for(Int_t i = 0 ; i < nTimeBins ; i++){
       if(fADCValuesHigh2x2[i] >= fL0Threshold || fADCValuesLow2x2[i] >= fL0Threshold) {
-       SetInput("PHOS_L0") ;
+       SetInput("0PH0") ;
        break;
       }
     }
@@ -585,9 +611,9 @@ 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
     if (fADCValuesHighnxn == 0) {
@@ -595,8 +621,8 @@ void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMo
       fADCValuesLownxn  = new Int_t[nTimeBins];
     }
 
-    pulse.SetAmplitude(maxtimeRn);
-    pulse.SetTZero(fnxnMaxAmp);
+    pulse.SetAmplitude(fnxnMaxAmp);
+    pulse.SetTZero(maxtimeRn);
     pulse.MakeSamples();
     pulse.GetSamples(fADCValuesHighnxn, fADCValuesLownxn) ;
     
@@ -626,35 +652,26 @@ void AliPHOSTrigger::SetTriggers(const TClonesArray * ampmatrix, const Int_t iMo
 }
 
 //____________________________________________________________________________
-void AliPHOSTrigger::Trigger() 
-{
-
-  //Main Method to select triggers.
-
-  AliRunLoader * rl = gAlice->GetRunLoader() ; 
-  TString fileName = rl->GetFileName() ; 
-  DoIt(fileName.Data()) ; 
-}
-
-//____________________________________________________________________________
-void AliPHOSTrigger::Trigger(const char * fileName) 
+void AliPHOSTrigger::Trigger(TClonesArray *digits) 
 {
-
   //Main Method to select triggers.
 
-  
-  DoIt(fileName) ; 
+  fDigitsList = digits;
+  DoIt() ; 
 }
 
 //____________________________________________________________________________
-void AliPHOSTrigger::DoIt(const char * fileName) 
+void AliPHOSTrigger::DoIt()
 {
   // does the trigger job
 
-  AliPHOSGetter * gime = AliPHOSGetter::Instance( fileName ) ;
+  AliRunLoader* rl = AliRunLoader::Instance() ;
+  AliPHOSLoader * phosLoader = static_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
   
-  //Get Geometry
-  const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
+  // Get PHOS Geometry object
+  AliPHOSGeometry *geom;
+  if (!(geom = AliPHOSGeometry::GetInstance())) 
+        geom = AliPHOSGeometry::GetInstance("IHEP","");
    
   //Define parameters
   Int_t nModules     = geom->GetNModules();
@@ -667,16 +684,16 @@ void AliPHOSTrigger::DoIt(const char * fileName)
 
   //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 
@@ -687,20 +704,17 @@ void AliPHOSTrigger::DoIt(const char * fileName)
   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) ;
   }
 
-  amptrus->Delete();
-  delete amptrus; amptrus=0;
-  ampmods->Delete();
-  delete ampmods; ampmods=0;
-  timeRtrus->Delete();
-  delete timeRtrus; timeRtrus=0;
+  fAmptrus->Delete();
+//   delete amptrus; amptrus=0;
+  fAmpmods->Delete();
+//   delete ampmods; ampmods=0;
+  fTimeRtrus->Delete();
+//   delete timeRtrus; timeRtrus=0;
   //Print();
 
 }