ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

/// \ingroup macros
/// \file fastMUONGen.C
/// \brief An example how to use the AliGenMUONCocktailpp generator
/// without GEANT simulation of the detector
///
/// \author H. Woehri,  A. De Falco, INFN Cagliari, April 2007
///
/// The macro switches on all decay modes for the resonances,
/// while for the minimum bias Pythia event we additionally
/// switch on the muonic decays of pions and Kaons
/// Its outcome can be further processed by the macro
/// fastMUONSim.C

#if !defined(__CINT__) || defined(__MAKECINT__)
#include "AliGenerator.h"
#include "AliRunLoader.h"
#include "AliRun.h"
#include "AliHeader.h"
#include "AliStack.h"
#include "AliGenCocktail.h"
#include "AliDecayerPythia.h"
#include "AliPDG.h"
#include "AliGenMUONCocktailpp.h"

#include "TParticle.h"
#endif

AliGenerator*  CreateGeneratorMC(Int_t mult);
Int_t SetupOutputDirectory();

/// The third argument \em mult allows to select at a "pre-trigger" level
/// events with "mult" muons in the MUON detector's phase space
/// window, which is defined in the method "CreateGeneratorMC(Int_t mult)".
/// Note that in this routine also a cut on the muon's origin
/// should be placed in order not to trigger on muons from pi/K decays
/// that were decayed by Pythia way inside the absorber or in the muon
/// spectrometer itself
void fastMUONGen(Int_t nev = 1, char* filename = "galice.root", Int_t mult = 2)
{
  Int_t runNumber = SetupOutputDirectory();
  gAlice->SetRunNumber(runNumber);
  printf("\n\n\n\nsetting run number to %d\n\n\n\n", runNumber);

  //  Update data base
  AliPDG::AddParticlesToPdgDataBase();
  //
  AliRunLoader* rl = AliRunLoader::Open(filename,"FASTRUN","recreate");
  rl->SetCompressionLevel(2);
  rl->SetNumberOfEventsPerFile(10000);
  rl->LoadKinematics("RECREATE");
  rl->MakeTree("E");
  gAlice->SetRunLoader(rl);
  //
  rl->MakeStack();
  AliStack* stack      = rl->Stack();
  AliHeader* header = rl->GetHeader();
  //
  //  Create and Initialize Generator
  AliGenerator *gener = CreateGeneratorMC(mult);
  gener->SetStack(stack);
  gener->Init();
  //
  for (int iev = 0; iev < nev; iev++) {

    if(iev%1000 == 0) printf("Event %d\n", iev);
    //  Initialize event
    header->Reset(0,iev);
    rl->SetEventNumber(iev);
    stack->Reset();
    rl->MakeTree("K");
    
    gener->Generate();
/*
    // Printing
    Int_t npart = stack->GetNprimary();
    for (Int_t part=0; part<npart; part++) {
      TParticle *MPart = stack->Particle(part);
      Int_t mpart  = MPart->GetPdgCode();
      printf("Particle %5d %5d  %5d\n", part, mpart, MPart->GetFirstMother());
    }
*/
      
    //  Finish event
    header->SetNprimary(stack->GetNprimary());
    header->SetNtrack(stack->GetNtrack());  
    //      I/O
    // 
    stack->FinishEvent();
    header->SetStack(stack);
    rl->TreeE()->Fill();
    rl->WriteKinematics("OVERWRITE");
  } // event loop
  
  gener->FinishRun();
  rl->WriteHeader("OVERWRITE");
  gener->Write();
  rl->Write();  
}
//===============================================
AliGenerator*  CreateGeneratorMC(Int_t mult)
{
    AliGenMUONCocktailpp* gener = new AliGenMUONCocktailpp();
    gener->SetPtRange(0.,100.);
    gener->SetYRange(-4.,-2.4);
    gener->SetPhiRange(0., 360.);
    gener->SetMuonMultiplicity(mult);
    gener->SetMuonPtCut(0.5);
    gener->SetMuonThetaRange(171.,178.);      
    gener->SetOrigin(0.,0.,0.); 
    gener->SetSigma(0.,0.,5.);
    gener->SetVertexSmear(kPerEvent);
    //for resonances: "kAll" all decay modes are openend
    gener->SetDecayModeResonance(kAll);  
    //for MC Pythia events: all decays, including muonic decays from pion and Kaons are opened
    gener->SetDecayModePythia(kAllMuonic); 
    gener->SetMuonOriginCut(-130.); //prevent the trigger muon(s) from decaying after 130 cm
    AliDecayerPythia* decayer = new AliDecayerPythia();
    gener->SetDecayer(decayer);
    return gener;
}
//===============================================
Int_t SetupOutputDirectory(){

  //Setting up the name for the output directory:
  static Int_t sseed = 0; // Set 0 to use the current time
  gRandom->SetSeed(sseed);
  UInt_t theSeed = gRandom->GetSeed();
  Int_t labIndex = 5; //1 subatech, 2 clermont, 3 Torino, 4 Orsay
                      // 5 Cagliari, etc...
  Int_t runNumber = (theSeed%100000000 + 100000000*labIndex);

  Char_t name[100];
  sprintf(name, "touch run_%d", runNumber);
  gSystem->Exec(name);

  return runNumber;
}
 fastMUONGen.C:1
 fastMUONGen.C:2
 fastMUONGen.C:3
 fastMUONGen.C:4
 fastMUONGen.C:5
 fastMUONGen.C:6
 fastMUONGen.C:7
 fastMUONGen.C:8
 fastMUONGen.C:9
 fastMUONGen.C:10
 fastMUONGen.C:11
 fastMUONGen.C:12
 fastMUONGen.C:13
 fastMUONGen.C:14
 fastMUONGen.C:15
 fastMUONGen.C:16
 fastMUONGen.C:17
 fastMUONGen.C:18
 fastMUONGen.C:19
 fastMUONGen.C:20
 fastMUONGen.C:21
 fastMUONGen.C:22
 fastMUONGen.C:23
 fastMUONGen.C:24
 fastMUONGen.C:25
 fastMUONGen.C:26
 fastMUONGen.C:27
 fastMUONGen.C:28
 fastMUONGen.C:29
 fastMUONGen.C:30
 fastMUONGen.C:31
 fastMUONGen.C:32
 fastMUONGen.C:33
 fastMUONGen.C:34
 fastMUONGen.C:35
 fastMUONGen.C:36
 fastMUONGen.C:37
 fastMUONGen.C:38
 fastMUONGen.C:39
 fastMUONGen.C:40
 fastMUONGen.C:41
 fastMUONGen.C:42
 fastMUONGen.C:43
 fastMUONGen.C:44
 fastMUONGen.C:45
 fastMUONGen.C:46
 fastMUONGen.C:47
 fastMUONGen.C:48
 fastMUONGen.C:49
 fastMUONGen.C:50
 fastMUONGen.C:51
 fastMUONGen.C:52
 fastMUONGen.C:53
 fastMUONGen.C:54
 fastMUONGen.C:55
 fastMUONGen.C:56
 fastMUONGen.C:57
 fastMUONGen.C:58
 fastMUONGen.C:59
 fastMUONGen.C:60
 fastMUONGen.C:61
 fastMUONGen.C:62
 fastMUONGen.C:63
 fastMUONGen.C:64
 fastMUONGen.C:65
 fastMUONGen.C:66
 fastMUONGen.C:67
 fastMUONGen.C:68
 fastMUONGen.C:69
 fastMUONGen.C:70
 fastMUONGen.C:71
 fastMUONGen.C:72
 fastMUONGen.C:73
 fastMUONGen.C:74
 fastMUONGen.C:75
 fastMUONGen.C:76
 fastMUONGen.C:77
 fastMUONGen.C:78
 fastMUONGen.C:79
 fastMUONGen.C:80
 fastMUONGen.C:81
 fastMUONGen.C:82
 fastMUONGen.C:83
 fastMUONGen.C:84
 fastMUONGen.C:85
 fastMUONGen.C:86
 fastMUONGen.C:87
 fastMUONGen.C:88
 fastMUONGen.C:89
 fastMUONGen.C:90
 fastMUONGen.C:91
 fastMUONGen.C:92
 fastMUONGen.C:93
 fastMUONGen.C:94
 fastMUONGen.C:95
 fastMUONGen.C:96
 fastMUONGen.C:97
 fastMUONGen.C:98
 fastMUONGen.C:99
 fastMUONGen.C:100
 fastMUONGen.C:101
 fastMUONGen.C:102
 fastMUONGen.C:103
 fastMUONGen.C:104
 fastMUONGen.C:105
 fastMUONGen.C:106
 fastMUONGen.C:107
 fastMUONGen.C:108
 fastMUONGen.C:109
 fastMUONGen.C:110
 fastMUONGen.C:111
 fastMUONGen.C:112
 fastMUONGen.C:113
 fastMUONGen.C:114
 fastMUONGen.C:115
 fastMUONGen.C:116
 fastMUONGen.C:117
 fastMUONGen.C:118
 fastMUONGen.C:119
 fastMUONGen.C:120
 fastMUONGen.C:121
 fastMUONGen.C:122
 fastMUONGen.C:123
 fastMUONGen.C:124
 fastMUONGen.C:125
 fastMUONGen.C:126
 fastMUONGen.C:127
 fastMUONGen.C:128
 fastMUONGen.C:129
 fastMUONGen.C:130
 fastMUONGen.C:131
 fastMUONGen.C:132
 fastMUONGen.C:133
 fastMUONGen.C:134
 fastMUONGen.C:135
 fastMUONGen.C:136
 fastMUONGen.C:137
 fastMUONGen.C:138
 fastMUONGen.C:139
 fastMUONGen.C:140
 fastMUONGen.C:141
 fastMUONGen.C:142
 fastMUONGen.C:143
 fastMUONGen.C:144
 fastMUONGen.C:145
 fastMUONGen.C:146
 fastMUONGen.C:147
 fastMUONGen.C:148
 fastMUONGen.C:149
 fastMUONGen.C:150
 fastMUONGen.C:151
 fastMUONGen.C:152
 fastMUONGen.C:153
 fastMUONGen.C:154
 fastMUONGen.C:155