Skip to content

Commit

Permalink
Merge branch 'swenzel/SimAndDigitsImprov'
Browse files Browse the repository at this point in the history
 * merging several improvements to code leading to overall ~20% gain
   in a PbPb simulation ("sim.C")
  • Loading branch information
sawenzel committed Jul 6, 2016
2 parents a5c0916 + 0557dfe commit cb0634c
Show file tree
Hide file tree
Showing 72 changed files with 1,529 additions and 994 deletions.
34 changes: 17 additions & 17 deletions ACORDE/ACORDEsim/AliACORDEv0.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -655,60 +655,60 @@ void AliACORDEv0::StepManager()
static Float_t eloss;
static Float_t step;
// scintillator volume
static Int_t idScint = TVirtualMC::GetMC()->VolId("ACORDE2");
static Int_t idScint = fMC->VolId("ACORDE2");

// local variables
Int_t copy;
TLorentzVector pos;
TLorentzVector mom;

// only charged tracks
if ( !TVirtualMC::GetMC()->TrackCharge() || !TVirtualMC::GetMC()->IsTrackAlive() ) return;
if ( !fMC->TrackCharge() || !fMC->IsTrackAlive() ) return;

// only in sensitive material
if (TVirtualMC::GetMC()->CurrentVolID(copy) == idScint) {
step += TVirtualMC::GetMC()->TrackStep();
eloss += TVirtualMC::GetMC()->Edep();
if (fMC->CurrentVolID(copy) == idScint) {
step += fMC->TrackStep();
eloss += fMC->Edep();
// set all hit variables except eloss which is resetted
// set volume variables
if (TVirtualMC::GetMC()->IsTrackEntering()) {
if (fMC->IsTrackEntering()) {
eloss = 0.0;
step = 0.0;
TVirtualMC::GetMC()->TrackPosition(pos);
TVirtualMC::GetMC()->TrackMomentum(mom);
fMC->TrackPosition(pos);
fMC->TrackMomentum(mom);
// hit
// [0] = PID
// [1-3] = x, y, z
// [4] = time
// [5-7] = px, py, pz
// [8] = energy
// [9] = energy loss
hits[0] = (Float_t ) TVirtualMC::GetMC()->TrackPid();
hits[0] = (Float_t ) fMC->TrackPid();
hits[1] = pos[0];
hits[2] = pos[1];
hits[3] = pos[2];
hits[4] = TVirtualMC::GetMC()->TrackTime();
hits[4] = fMC->TrackTime();
hits[5] = mom[0];
hits[6] = mom[1];
hits[7] = mom[2];
hits[8] = TVirtualMC::GetMC()->Etot();
hits[8] = fMC->Etot();
// volume:
// [0] = module number 1-60 (1==>(0-0), 60 (5-9)
// [1] = Plastic number: 0 (down) to 1 (up)
Int_t copyPlastic; // plastic: down=1, up=2
Int_t copyModule; // module: 1-60
TVirtualMC::GetMC()->CurrentVolID(copyPlastic);
TVirtualMC::GetMC()->CurrentVolOffID(1, copyModule);
fMC->CurrentVolID(copyPlastic);
fMC->CurrentVolOffID(1, copyModule);
// module
vol[0] = copyModule;
// plastic: 0 = down, 1 = up
vol[1] = copyPlastic;
} // end if TVirtualMC::GetMC()->IsTrackEntering()
} // end if fMC->IsTrackEntering()

// set hit[9] = total energy loss and book hit
if( TVirtualMC::GetMC()->IsTrackExiting() ||
TVirtualMC::GetMC()->IsTrackStop() ||
TVirtualMC::GetMC()->IsTrackDisappeared()){
if( fMC->IsTrackExiting() ||
fMC->IsTrackStop() ||
fMC->IsTrackDisappeared()){
hits[9] = eloss;
hits[10] = step;
eloss = 0.0;
Expand Down
34 changes: 17 additions & 17 deletions ACORDE/ACORDEsim/AliACORDEv1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -727,63 +727,63 @@ void AliACORDEv1::StepManager()
static Float_t eloss;
static Float_t step;
// scintillator volume
static Int_t idScint = TVirtualMC::GetMC()->VolId("ACORDESCINTILLATORMODULE");
static Int_t idScint = fMC->VolId("ACORDESCINTILLATORMODULE");
// local variables
Int_t copy;
TLorentzVector pos;
TLorentzVector mom;

// only charged tracks
if ( !TVirtualMC::GetMC()->TrackCharge() || !TVirtualMC::GetMC()->IsTrackAlive() ) return;
if ( !fMC->TrackCharge() || !fMC->IsTrackAlive() ) return;

// only in sensitive material
if (TVirtualMC::GetMC()->CurrentVolID(copy) == idScint) {
if (fMC->CurrentVolID(copy) == idScint) {

step += TVirtualMC::GetMC()->TrackStep();
eloss += TVirtualMC::GetMC()->Edep();
step += fMC->TrackStep();
eloss += fMC->Edep();
// set all hit variables except eloss which is resetted
// set volume variables
if (TVirtualMC::GetMC()->IsTrackEntering()) {
if (fMC->IsTrackEntering()) {
eloss = 0.0;
step = 0.0;
TVirtualMC::GetMC()->TrackPosition(pos);
TVirtualMC::GetMC()->TrackMomentum(mom);
fMC->TrackPosition(pos);
fMC->TrackMomentum(mom);
// hit
// [0] = PID
// [1-3] = x, y, z
// [4] = time
// [5-7] = px, py, pz
// [8] = energy
// [9] = energy loss
hits[0] = (Float_t ) TVirtualMC::GetMC()->TrackPid();
hits[0] = (Float_t ) fMC->TrackPid();


hits[1] = pos[0];
hits[2] = pos[1];
hits[3] = pos[2];
hits[4] = TVirtualMC::GetMC()->TrackTime();
hits[4] = fMC->TrackTime();
hits[5] = mom[0];
hits[6] = mom[1];
hits[7] = mom[2];
hits[8] = TVirtualMC::GetMC()->Etot();
hits[8] = fMC->Etot();
// volume:
// [0] = module number 1-60 (1==>(0-0), 60 (5-9)
// [1] = Plastic number: 0 (down) to 1 (up)
Int_t copyPlastic; // plastic: down=1, up=2
Int_t copyModule; // module: 1-60
TVirtualMC::GetMC()->CurrentVolID(copyPlastic);
TVirtualMC::GetMC()->CurrentVolOffID(1, copyModule);
fMC->CurrentVolID(copyPlastic);
fMC->CurrentVolOffID(1, copyModule);
// module
vol[0] = copyModule;
// plastic: 0 = down, 1 = up
vol[1] = copyPlastic - 4 ; // !!!!!!!
// vol[1] = copyPlastic;
} // end if TVirtualMC::GetMC()->IsTrackEntering()
} // end if fMC->IsTrackEntering()

// set hit[9] = total energy loss and book hit
if( TVirtualMC::GetMC()->IsTrackExiting() ||
TVirtualMC::GetMC()->IsTrackStop() ||
TVirtualMC::GetMC()->IsTrackDisappeared()){
if( fMC->IsTrackExiting() ||
fMC->IsTrackStop() ||
fMC->IsTrackDisappeared()){
hits[9] = eloss;
hits[10] = step;
eloss = 0.0;
Expand Down
38 changes: 19 additions & 19 deletions AD/ADsim/AliADv1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1079,25 +1079,25 @@ void AliADv1::StepManager()


// Get sensitive volumes id (scintillator pads)
static Int_t idADA = gMC->VolId( "ADApad" );
static Int_t idADC = gMC->VolId( "ADCpad" );
// static Int_t idADCh = gMC->VolId( "ADCpadH" );
static Int_t idADA = fMC->VolId( "ADApad" );
static Int_t idADC = fMC->VolId( "ADCpad" );
// static Int_t idADCh = fMC->VolId( "ADCpadH" );

static Bool_t fOnlyOnce = kTRUE;
if (fOnlyOnce) {
//printf(" gMC->VolId(\"ADApad\" ) = %3d\n", idADA);
//printf(" gMC->VolId(\"ADCpad\" ) = %3d\n", idADC);
// printf(" gMC->VolId(\"ADCpadH\") = %3d\n", idADCh);
//printf(" fMC->VolId(\"ADApad\" ) = %3d\n", idADA);
//printf(" fMC->VolId(\"ADCpad\" ) = %3d\n", idADC);
// printf(" fMC->VolId(\"ADCpadH\") = %3d\n", idADCh);
fOnlyOnce = kFALSE;
}

// We keep only charged tracks :
// if ( !gMC->TrackCharge() || !gMC->IsTrackAlive() ) return;
// if ( !fMC->TrackCharge() || !fMC->IsTrackAlive() ) return;
// We keep charged and non-charged tracks :
if ( !gMC->IsTrackAlive() ) return;
if ( !fMC->IsTrackAlive() ) return;

Int_t copy;
Int_t current_volid = gMC->CurrentVolID( copy );
Int_t current_volid = fMC->CurrentVolID( copy );

// check is the track is in a sensitive volume
// if( current_volid != idADA && current_volid != idADC && current_volid != idADCh ) {
Expand All @@ -1108,16 +1108,16 @@ void AliADv1::StepManager()
// First read the position, otherwise weird results! //ecv
Double_t s[3];
Float_t x[3];
gMC->TrackPosition( s[0], s[1], s[2] );
fMC->TrackPosition( s[0], s[1], s[2] );
for ( Int_t j=0; j<3; j++ ) x[j] = s[j];

// Get sector copy (1,2,3,4) ( 1 level up from pad )
Int_t sect;
gMC->CurrentVolOffID( 1, sect );
fMC->CurrentVolOffID( 1, sect );

// Get Detector copy (1,2) ( 2 levels up from pad )
Int_t detc;
gMC->CurrentVolOffID( 2, detc );
fMC->CurrentVolOffID( 2, detc );

// Set detector type: ADA or ADC
Int_t ADlayer = (current_volid == idADC ) ? 0 : 2;
Expand Down Expand Up @@ -1147,8 +1147,8 @@ void AliADv1::StepManager()
photoCathodeEfficiency = fADAPhotoCathodeEfficiency;
}

Float_t destep_ad = gMC->Edep();
Float_t step_ad = gMC->TrackStep();
Float_t destep_ad = fMC->Edep();
Float_t step_ad = fMC->TrackStep();
Int_t nPhotonsInStep_ad = Int_t( destep_ad / (lightYield_ad * 1e-9) );
nPhotonsInStep_ad = gRandom->Poisson( nPhotonsInStep_ad );

Expand All @@ -1161,10 +1161,10 @@ void AliADv1::StepManager()
eloss_ad += destep_ad;
tlength_ad += step_ad;

if ( gMC->IsTrackEntering() ) {
if ( fMC->IsTrackEntering() ) {
nPhotons_ad = nPhotonsInStep_ad;
Double_t p[4];
gMC->TrackMomentum( p[0], p[1], p[2], p[3] );
fMC->TrackMomentum( p[0], p[1], p[2], p[3] );
Float_t pt = TMath::Sqrt( p[0]*p[0] + p[1]*p[1] + p[2]*p[2] );
TParticle *par = gAlice->GetMCApp()->Particle(gAlice->GetMCApp()->GetCurrentTrackNumber());
Int_t imo = par->GetFirstMother();
Expand All @@ -1187,7 +1187,7 @@ void AliADv1::StepManager()
hits_ad[5] = p[0]; // Px
hits_ad[6] = p[1]; // Py
hits_ad[7] = p[2]; // Pz
hits_ad[8] = 1.0e09*gMC->TrackTime(); // in ns!
hits_ad[8] = 1.0e09*fMC->TrackTime(); // in ns!

tlength_ad = 0.0;
eloss_ad = 0.0;
Expand All @@ -1197,7 +1197,7 @@ void AliADv1::StepManager()

nPhotons_ad += nPhotonsInStep_ad;

if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) {
if( fMC->IsTrackExiting() || fMC->IsTrackStop() || fMC->IsTrackDisappeared() ) {

// Set integer values
vol_ad[3] = nPhotons_ad;
Expand All @@ -1215,7 +1215,7 @@ void AliADv1::StepManager()
}

//Track reference
if( gMC->IsTrackEntering() || gMC->IsTrackExiting() ) AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kAD);
if( fMC->IsTrackEntering() || fMC->IsTrackExiting() ) AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kAD);
}
//_________________________________________________________
void AliADv1::AddHit(Int_t track, Int_t *vol, Float_t *hits)
Expand Down
16 changes: 8 additions & 8 deletions BCM/AliBCM.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,27 @@ void AliBCM::StepManager()
Int_t copy = -1;


if (TVirtualMC::GetMC()->TrackCharge() &&
TVirtualMC::GetMC()->CurrentVolID(copy) == fVolId) {
if (fMC->TrackCharge() &&
fMC->CurrentVolID(copy) == fVolId) {
// Charged particle inside sensitive volume
//
// Entering
if (TVirtualMC::GetMC()->IsTrackEntering()) {
if (fMC->IsTrackEntering()) {
edepT = 0.;
TVirtualMC::GetMC()->TrackPosition(xh[0],xh[1],xh[2]);
xh[3] = TVirtualMC::GetMC()->TrackTime();
fMC->TrackPosition(xh[0],xh[1],xh[2]);
xh[3] = fMC->TrackTime();
}

//
// Any step
if ((edep = TVirtualMC::GetMC()->Edep()) > 0.) {
if ((edep = fMC->Edep()) > 0.) {
Double_t x[3];
TVirtualMC::GetMC()->TrackPosition(x[0],x[1],x[2]);
fMC->TrackPosition(x[0],x[1],x[2]);
edepT += edep;
}
//
// Exiting
if(TVirtualMC::GetMC()->IsTrackExiting()||TVirtualMC::GetMC()->IsTrackStop()||TVirtualMC::GetMC()->IsTrackDisappeared())
if(fMC->IsTrackExiting()||fMC->IsTrackStop()||fMC->IsTrackDisappeared())
{
Int_t track = gAlice->GetMCApp()->GetCurrentTrackNumber();
TClonesArray &lhits = *fHits;
Expand Down
22 changes: 0 additions & 22 deletions EMCAL/EMCALbase/AliEMCALDigit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -232,28 +232,6 @@ void AliEMCALDigit::Clear(const Option_t*)

}

//____________________________________________________________________________
Int_t AliEMCALDigit::Compare(const TObject * obj) const
{
// Compares two digits with respect to its Id
// to sort according increasing Id

Int_t rv = 2 ;

AliEMCALDigit * digit = (AliEMCALDigit *)obj ;

Int_t iddiff = fId - digit->GetId() ;

if ( iddiff > 0 )
rv = 1 ;
else if ( iddiff < 0 )
rv = -1 ;
else
rv = 0 ;

return rv ;

}

//____________________________________________________________________________
Float_t AliEMCALDigit::GetEta() const
Expand Down
20 changes: 20 additions & 0 deletions EMCAL/EMCALbase/AliEMCALDigit.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,24 @@ class AliEMCALDigit : public AliDigitNew {
ClassDef(AliEMCALDigit,7) // Digit in EMCAL
} ;

// inline definitions

//____________________________________________________________________________
inline Int_t AliEMCALDigit::Compare(const TObject * obj) const
{
// Compares two digits with respect to its Id
// to sort according increasing Id
AliEMCALDigit * digit = (AliEMCALDigit *)obj ;

Int_t iddiff = fId - digit->GetId() ;

if ( iddiff > 0 )
return 1 ;
else if ( iddiff < 0 )
return -1 ;
else
return 0 ;
}


#endif // ALIEMCALDIGIT_H
12 changes: 7 additions & 5 deletions EMCAL/EMCALbase/AliEMCALSDigitizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#include "AliEMCALSDigitizer.h"
#include "AliEMCALGeometry.h"
#include "AliEMCALSimParam.h"
#include "AliSort.h"

ClassImp(AliEMCALSDigitizer)

Expand Down Expand Up @@ -295,7 +296,7 @@ void AliEMCALSDigitizer::Digitize(Option_t *option)
Int_t nHit = fHits->GetEntriesFast();
for(iHit = 0; iHit< nHit;iHit++){

AliEMCALHit * hit = dynamic_cast<AliEMCALHit*>(fHits->At(iHit)) ;
AliEMCALHit * hit = static_cast<AliEMCALHit*>(fHits->UncheckedAt(iHit)) ;
AliEMCALDigit * curSDigit = 0 ;
AliEMCALDigit * sdigit = 0 ;
Bool_t newsdigit = kTRUE;
Expand Down Expand Up @@ -324,7 +325,7 @@ void AliEMCALSDigitizer::Digitize(Option_t *option)

if(curSDigit != 0){
for(Int_t check= 0; check < nSdigits ; check++) {
sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(check)) ;
sdigit = static_cast<AliEMCALDigit *>(sdigits->UncheckedAt(check)) ;
if(sdigit){
if( sdigit->GetId() == curSDigit->GetId()) { // Are we in the same ECAL tower ?
*sdigit = *sdigit + *curSDigit;
Expand Down Expand Up @@ -352,13 +353,14 @@ void AliEMCALSDigitizer::Digitize(Option_t *option)
}//fHits is not NULL
else AliFatal("fHit is NULL!");

sdigits->Sort() ;

// sdigits->Sort() ;
AliSort::TClonesArraySort<AliEMCALDigit>(sdigits);

nSdigits = sdigits->GetEntriesFast() ;
fSDigitsInRun += nSdigits ;

for (iSDigit = 0 ; iSDigit < sdigits->GetEntriesFast() ; iSDigit++) {
AliEMCALDigit * sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(iSDigit)) ;
AliEMCALDigit * sdigit = static_cast<AliEMCALDigit *>(sdigits->UncheckedAt(iSDigit)) ;
if(sdigit)sdigit->SetIndexInList(iSDigit) ;
else AliFatal("sdigit is NULL!");
}
Expand Down
Loading

0 comments on commit cb0634c

Please sign in to comment.