Commit 6ca3e66e authored by Breno Rilho Lemos's avatar Breno Rilho Lemos 💬

Generate animations for every event in file

parent c3985c40
...@@ -34,9 +34,6 @@ ...@@ -34,9 +34,6 @@
Int_t esd_event_id = 0; // global variable to store unique event id Int_t esd_event_id = 0; // global variable to store unique event id
Int_t smallEventID = 0; // is equal to esd-event-id until the selected event (one with an appropriate number of tracks) is reached
Int_t mediumEventID = 0; // for events with ~200 tracks
Int_t largeEventID = 0; // for events with many many tracks
class AliAnalysisTaskMyTask; // your analysis class class AliAnalysisTaskMyTask; // your analysis class
...@@ -127,69 +124,82 @@ void AliAnalysisTaskMyTask::UserExec(Option_t *) ...@@ -127,69 +124,82 @@ void AliAnalysisTaskMyTask::UserExec(Option_t *)
s_event >> selectedEventID; s_event >> selectedEventID;
s_event.close(); s_event.close();
ofstream esd_detail; if(selectedEventID == -1) {
esd_detail.open ("esd-detail.dat",std::ofstream::app);
ofstream events_number;
events_number.open ("events_number.dat",std::ofstream::out);
fESD = dynamic_cast<AliESDEvent*>(InputEvent()); // get an event (called fESD) from the input file events_number << esd_event_id+1;
// there's another event format (ESD) which works in a similar way events_number.close();
} else {
if(!fESD) return; // if the pointer to the event is empty (getting it failed) skip this event ofstream esd_detail;
// example part: i'll show how to loop over the tracks in an event esd_detail.open ("esd-detail.dat",std::ofstream::app);
// and extract some information from them which we'll store in a histogram
Int_t iTracks(fESD->GetNumberOfTracks()); // see how many tracks there are in the event
Double_t Vx = 0.01 * fESD->GetPrimaryVertex()->GetX(); // gets vertexes from individual events, in METERS fESD = dynamic_cast<AliESDEvent*>(InputEvent()); // get an event (called fESD) from the input file
Double_t Vy = 0.01 * fESD->GetPrimaryVertex()->GetY();
Double_t Vz = 0.01 * fESD->GetPrimaryVertex()->GetZ();
Double_t MagneticField = 0.1 * fESD->GetMagneticField(); // gets magnetic field, in TESLA
// there's another event format (ESD) which works in a similar way
/*
Assumed Units: Mass (GeV/c^2)[CONFIRMED] || Energy (GeV) || Momentum (GeV/c) || Charge (* 1.6*10^-19 C) if(!fESD) return; // if the pointer to the event is empty (getting it failed) skip this event
// example part: i'll show how to loop over the tracks in an event
// and extract some information from them which we'll store in a histogram
*/ Int_t iTracks(fESD->GetNumberOfTracks()); // see how many tracks there are in the event
if(selectedEventID == esd_event_id) { // when we get to the selected event, fill histograms and write data Double_t Vx = 0.01 * fESD->GetPrimaryVertex()->GetX(); // gets vertexes from individual events, in METERS
Double_t Vy = 0.01 * fESD->GetPrimaryVertex()->GetY();
Double_t Vz = 0.01 * fESD->GetPrimaryVertex()->GetZ();
Double_t MagneticField = 0.1 * fESD->GetMagneticField(); // gets magnetic field, in TESLA
for(Int_t i(0); i < iTracks; i++) { // loop over all these tracks
AliESDtrack* track = static_cast<AliESDtrack*>(fESD->GetTrack(i)); // get a track (type AliESDtrack) from the event /*
if(!track) continue; // if we failed, skip this track Assumed Units: Mass (GeV/c^2)[CONFIRMED] || Energy (GeV) || Momentum (GeV/c) || Charge (* 1.6*10^-19 C)
Double_t Mass = track->M(); // returns the pion mass, if the particle can't be identified properly */
Double_t Energy = track->E(); // Returns the energy of the particle given its assumed mass, but assumes the pion mass if the particle can't be identified properly.
Double_t Px = track->Px(); if(selectedEventID == esd_event_id) { // when we get to the selected event, fill histograms and write data
Double_t Py = track->Py();
Double_t Pt = track->Pt(); // transversal momentum, in case we need it
Double_t Pz = track->Pz();
Double_t Charge = track->Charge(); for(Int_t i(0); i < iTracks; i++) { // loop over all these tracks
// Add VERTEX (x, y, z), MASS, CHARGE and MOMENTUM (x, y, z) to esd-detail.dat file AliESDtrack* track = static_cast<AliESDtrack*>(fESD->GetTrack(i)); // get a track (type AliESDtrack) from the event
esd_detail << Vx << " " << Vy << " " << Vz << " ";
esd_detail << Mass << " " << Charge << " ";
esd_detail << Px << " " << Py << " " << Pz << endl;
fHistPt->Fill(Pt); // plot the pt value of the track in a histogram if(!track) continue; // if we failed, skip this track
fHistMass->Fill(Mass); Double_t Mass = track->M(); // returns the pion mass, if the particle can't be identified properly
Double_t Energy = track->E(); // Returns the energy of the particle given its assumed mass, but assumes the pion mass if the particle can't be identified properly.
} Double_t Px = track->Px();
Double_t Py = track->Py();
Double_t Pt = track->Pt(); // transversal momentum, in case we need it
Double_t Pz = track->Pz();
} Double_t Charge = track->Charge();
// Add VERTEX (x, y, z), MASS, CHARGE and MOMENTUM (x, y, z) to esd-detail.dat file
esd_detail << Vx << " " << Vy << " " << Vz << " ";
esd_detail << Mass << " " << Charge << " ";
esd_detail << Px << " " << Py << " " << Pz << endl;
fHistPt->Fill(Pt); // plot the pt value of the track in a histogram
fHistMass->Fill(Mass);
}
}
esd_detail.close();
}
Event++; Event++;
esd_event_id++; // Increment global esd_event_id esd_event_id++; // Increment global esd_event_id
fHistEvents->Fill(Event); fHistEvents->Fill(Event);
esd_detail.close();
// continue until all the tracks are processed // continue until all the tracks are processed
PostData(1, fOutputList); // stream the results the analysis of this event to PostData(1, fOutputList); // stream the results the analysis of this event to
......
...@@ -9,7 +9,10 @@ ...@@ -9,7 +9,10 @@
int runAnalysis(int selected_event=0) int runAnalysis(int selected_event=0)
{ {
// Erase output txt files // Erase output txt files
ofstream esd_detail, s_event; ofstream esd_detail, s_event, events_number;
events_number.open ("events_number.dat");
events_number.close();
s_event.open ("s-event.dat"); s_event.open ("s-event.dat");
s_event << selected_event; s_event << selected_event;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# animate_particles.py - Animate HEP events # animate_particles.py - Animate HEP events
# #
# For console only rendering (example): # For console only rendering (example):
# $ blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=1 -camera="BarrelCamera" -datafile="esd-detail.dat" -simulated_t=0.02 -fps=24 -resolution=100 -stamp_note="Texto no canto" # $ blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=1 -camera="BarrelCamera" -datafile="esd-detail.dat" -n_event=0 -simulated_t=0.02 -fps=24 -resolution=100 -stamp_note="Texto no canto"
# #
import os import os
...@@ -34,6 +34,7 @@ parser.add_argument('-simulated_t','--simulated_t') ...@@ -34,6 +34,7 @@ parser.add_argument('-simulated_t','--simulated_t')
parser.add_argument('-fps','--fps') parser.add_argument('-fps','--fps')
parser.add_argument('-resolution','--resolution_percent') parser.add_argument('-resolution','--resolution_percent')
parser.add_argument('-stamp_note','--stamp_note') parser.add_argument('-stamp_note','--stamp_note')
parser.add_argument('-n_event','--n_event')
args = parser.parse_args() args = parser.parse_args()
bpy.context.user_preferences.view.show_splash = False bpy.context.user_preferences.view.show_splash = False
...@@ -43,6 +44,7 @@ exec(compile(open(filename).read(), filename, 'exec')) ...@@ -43,6 +44,7 @@ exec(compile(open(filename).read(), filename, 'exec'))
# Set animation parameters # Set animation parameters
r_part = float(args.r_part) # Particle radius r_part = float(args.r_part) # Particle radius
n_event = str(args.n_event) # Event number for video name
simulated_t = float(args.simulated_t) # in microsseconds simulated_t = float(args.simulated_t) # in microsseconds
duration = int(args.duration) # in seconds duration = int(args.duration) # in seconds
fps = int(args.fps) fps = int(args.fps)
...@@ -65,7 +67,7 @@ driver.configure(renderCamera, duration, fps, simulated_t, outputPath, fileIdent ...@@ -65,7 +67,7 @@ driver.configure(renderCamera, duration, fps, simulated_t, outputPath, fileIdent
""" """
# Create and configure animation driver # Create and configure animation driver
driver = dataDriver("AlirootFileGenerator",args.datafile) # Simple dataDriver takes one parameters: filename driver = dataDriver("AlirootFileGenerator",n_event,args.datafile) # Simple dataDriver takes one parameters: filename
driver.configure(renderCamera, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent) driver.configure(renderCamera, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent)
### Build scene ### Build scene
......
...@@ -46,7 +46,7 @@ class animationDriver: ...@@ -46,7 +46,7 @@ class animationDriver:
bcsr.ffmpeg.packetsize = 2048 bcsr.ffmpeg.packetsize = 2048
bcsr.ffmpeg.muxrate = 10080000 bcsr.ffmpeg.muxrate = 10080000
xpixels = int(bcsr.resolution_percentage * bcsr.resolution_x / 100) xpixels = int(bcsr.resolution_percentage * bcsr.resolution_x / 100)
output_prefix=fileIdentifier+str(xpixels)+"px_"+self.name output_prefix=fileIdentifier+str(xpixels)+"px_"+self.name+self.renderCamera
bcsr.filepath = "/tmp/blender/"+output_prefix bcsr.filepath = "/tmp/blender/"+output_prefix
class genDriver(animationDriver): # A driver for particle generators class genDriver(animationDriver): # A driver for particle generators
...@@ -68,8 +68,8 @@ class genDriver(animationDriver): # A driver for particle generators ...@@ -68,8 +68,8 @@ class genDriver(animationDriver): # A driver for particle generators
return particles; return particles;
class dataDriver(animationDriver): # A driver for data from files. class dataDriver(animationDriver): # A driver for data from files.
def __init__(self,name,datafile): def __init__(self,name,nEvent,datafile):
self.name = name+"_"+datafile+"_" self.name = name+"_"+datafile+"_Event_"+nEvent+"_"
self.datafile = datafile self.datafile = datafile
def getParticles(self): # Create particles acording to parameters from file def getParticles(self): # Create particles acording to parameters from file
# Count number of lines in file = number of particles # Count number of lines in file = number of particles
......
...@@ -12,7 +12,7 @@ export BLENDER_SCRIPT_DIR=$(pwd)/animate/ ...@@ -12,7 +12,7 @@ export BLENDER_SCRIPT_DIR=$(pwd)/animate/
# Directory where output animations should be placed # Directory where output animations should be placed
export BLENDER_OUTPUT=$(pwd)/output/ export BLENDER_OUTPUT=$(pwd)/output/
# alienv working directory # alienv working directory
export ALIENV_WORK_DIR=/mnt/SSD/schnorr/ALICE/sw/ export ALIENV_WORK_DIR=/home/tropos/alice/sw
export ALIENV_ID=AliPhysics/latest-aliroot5-user export ALIENV_ID=AliPhysics/latest-aliroot5-user
# Put blender 2.79b in the PATH env var # Put blender 2.79b in the PATH env var
export PATH="/home/schnorr/install/blender-2.79-linux-glibc219-x86_64/:$PATH" export PATH="/home/schnorr/install/blender-2.79-linux-glibc219-x86_64/:$PATH"
...@@ -71,6 +71,7 @@ fi ...@@ -71,6 +71,7 @@ fi
if [ -z $DEFAULT_ANIMATION ]; then if [ -z $DEFAULT_ANIMATION ]; then
# Verify if AliESDs.root is here # Verify if AliESDs.root is here
# #ALIESD_ROOT_FILE=$(pwd)/AliESDs.root # #ALIESD_ROOT_FILE=$(pwd)/AliESDs.root
mkdir --verbose -p ${BLENDER_OUTPUT}
mv --verbose $(pwd)/AliESDs.root ${ALIROOT_SCRIPT_DIR} mv --verbose $(pwd)/AliESDs.root ${ALIROOT_SCRIPT_DIR}
############################## ##############################
...@@ -80,19 +81,37 @@ if [ -z $DEFAULT_ANIMATION ]; then ...@@ -80,19 +81,37 @@ if [ -z $DEFAULT_ANIMATION ]; then
pushd ${ALIROOT_SCRIPT_DIR} pushd ${ALIROOT_SCRIPT_DIR}
# #rm --verbose AliESDs.root # #rm --verbose AliESDs.root
# #ln --verbose -s $ALIESD_ROOT_FILE AliESDs.root # #ln --verbose -s $ALIESD_ROOT_FILE AliESDs.root
aliroot -q -b "runAnalysis.C(2)" aliroot -q -b "runAnalysis.C(-1)"
ls -lh esd-detail.dat ls -lh events_number.dat
#done n_events=`more events_number.dat`
for ((i=0; i<n_events; i++))
do
aliroot -q -b "runAnalysis.C($i)"
# Phase 2: Blender animate
mv --verbose ${ALIROOT_SCRIPT_DIR}/esd-detail.dat ${BLENDER_SCRIPT_DIR}
pushd ${BLENDER_SCRIPT_DIR}
for type in "BarrelCamera" "OverviewCamera" "ForwardCamera"; do
blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=1 -camera=${type} -datafile="esd-detail.dat" -n_event=$i -simulated_t=0.02 -fps=5 -resolution=50 -stamp_note="Texto no canto"
echo "${type} for event $i done."
done
popd
#mkdir --verbose -p ${BLENDER_OUTPUT}
#mv --verbose /tmp/blender ${BLENDER_OUTPUT}
echo "EVENT $i DONE."
done
popd popd
mv --verbose /tmp/blender ${BLENDER_OUTPUT}
############################## ##############################
# Phase 2: blender animate # # Phase 2: blender animate #
############################## ##############################
mv --verbose ${ALIROOT_SCRIPT_DIR}/esd-detail.dat ${BLENDER_SCRIPT_DIR} # mv --verbose ${ALIROOT_SCRIPT_DIR}/esd-detail.dat ${BLENDER_SCRIPT_DIR}
pushd ${BLENDER_SCRIPT_DIR} # pushd ${BLENDER_SCRIPT_DIR}
blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=2 -camera="BarrelCamera" -datafile="esd-detail.dat" -simulated_t=0.02 -fps=5 -resolution=100 -stamp_note="Texto no canto" # blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=2 -camera="BarrelCamera" -datafile="esd-detail.dat" -simulated_t=0.02 -fps=5 -resolution=100 -stamp_note="Texto no canto"
popd # popd
mkdir --verbose -p ${BLENDER_OUTPUT} # mkdir --verbose -p ${BLENDER_OUTPUT}
mv --verbose /tmp/blender ${BLENDER_OUTPUT} # mv --verbose /tmp/blender ${BLENDER_OUTPUT}
echo "Done." # echo "Done."
fi fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment