+//_______________________________________________________________________
+Bool_t AliSimulation::RunLego(const char *setup, Int_t nc1, Float_t c1min,
+ Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
+ Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener, Int_t nev)
+{
+ //
+ // Generates lego plots of:
+ // - radiation length map phi vs theta
+ // - radiation length map phi vs eta
+ // - interaction length map
+ // - g/cm2 length map
+ //
+ // ntheta bins in theta, eta
+ // themin minimum angle in theta (degrees)
+ // themax maximum angle in theta (degrees)
+ // nphi bins in phi
+ // phimin minimum angle in phi (degrees)
+ // phimax maximum angle in phi (degrees)
+ // rmin minimum radius
+ // rmax maximum radius
+ //
+ //
+ // The number of events generated = ntheta*nphi
+ // run input parameters in macro setup (default="Config.C")
+ //
+ // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
+ //Begin_Html
+ /*
+ <img src="picts/AliRunLego1.gif">
+ */
+ //End_Html
+ //Begin_Html
+ /*
+ <img src="picts/AliRunLego2.gif">
+ */
+ //End_Html
+ //Begin_Html
+ /*
+ <img src="picts/AliRunLego3.gif">
+ */
+ //End_Html
+ //
+
+// run the generation and simulation
+
+ AliCodeTimerAuto("")
+
+ // initialize CDB storage and run number from external environment
+ // (either CDB manager or AliSimulation setters)
+ InitCDB();
+ InitRunNumber();
+ SetCDBLock();
+
+ if (!gAlice) {
+ AliError("no gAlice object. Restart aliroot and try again.");
+ return kFALSE;
+ }
+ if (gAlice->Modules()->GetEntries() > 0) {
+ AliError("gAlice was already run. Restart aliroot and try again.");
+ return kFALSE;
+ }
+
+ AliInfo(Form("initializing gAlice with config file %s",
+ fConfigFileName.Data()));
+
+ // Number of events
+ if (nev == -1) nev = nc1 * nc2;
+
+ // check if initialisation has been done
+ // If runloader has been initialized, set the number of events per file to nc1 * nc2
+
+ // Set new generator
+ if (!gener) gener = new AliLegoGenerator();
+ //
+ // Configure Generator
+
+ gener->SetRadiusRange(rmin, rmax);
+ gener->SetZMax(zmax);
+ gener->SetCoor1Range(nc1, c1min, c1max);
+ gener->SetCoor2Range(nc2, c2min, c2max);
+
+
+ //Create Lego object
+ fLego = new AliLego("lego",gener);
+
+ //__________________________________________________________________________
+
+ gAlice->Announce();
+
+ gROOT->LoadMacro(setup);
+ gInterpreter->ProcessLine(gAlice->GetConfigFunction());
+
+ if(AliCDBManager::Instance()->GetRun() >= 0) {
+ SetRunNumber(AliCDBManager::Instance()->GetRun());
+ } else {
+ AliWarning("Run number not initialized!!");
+ }
+
+ AliRunLoader::Instance()->CdGAFile();
+
+ AliPDG::AddParticlesToPdgDataBase();
+
+ gAlice->GetMCApp()->Init();
+
+ gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
+
+
+ //Must be here because some MCs (G4) adds detectors here and not in Config.C
+ gAlice->InitLoaders();
+ AliRunLoader::Instance()->MakeTree("E");
+
+ //
+ // Save stuff at the beginning of the file to avoid file corruption
+ AliRunLoader::Instance()->CdGAFile();
+ gAlice->Write();
+
+ //Save current generator
+ AliGenerator *gen=gAlice->GetMCApp()->Generator();
+ gAlice->GetMCApp()->ResetGenerator(gener);
+ //Prepare MC for Lego Run
+ gMC->InitLego();
+
+ //Run Lego Object
+
+
+ AliRunLoader::Instance()->SetNumberOfEventsPerFile(nev);
+ gMC->ProcessRun(nev);
+
+ // End of this run, close files
+ FinishRun();
+ // Restore current generator
+ gAlice->GetMCApp()->ResetGenerator(gen);
+ // Delete Lego Object
+ delete fLego;
+
+ return kTRUE;
+}
+