Commit 80233ed8 authored by Breno Rilho Lemos's avatar Breno Rilho Lemos 💬

Add options 'blendersave', 'minavgpt'; lighting adjustments

parent 5e6dcaa0
......@@ -36,6 +36,8 @@
Int_t esd_event_id = 0; // global variable to store unique event id
Double_t highAvgPz, lowAvgPz, highAvgPzEvent, lowAvgPzEvent; //variables to store info about highest and lowest <Pz> values
Double_t highAvgPt, highAvgPtEvent; //variables to store info about highest and lowest <Pt> values
class AliAnalysisTaskMyTask; // your analysis class
......@@ -44,14 +46,14 @@ using namespace std; // std namespace: so you can do things like 'cou
ClassImp(AliAnalysisTaskMyTask) // classimp: necessary for root
AliAnalysisTaskMyTask::AliAnalysisTaskMyTask() : AliAnalysisTaskSE(),
fESD(0), fOutputList(0), fHistPt(0), fHistAvgPz(0), fHistMass(0)
fESD(0), fOutputList(0), fHistPt(0), fHistAvgPz(0), fHistAvgPt(0), fHistMass(0)
{
// default constructor, don't allocate memory here!
// this is used by root for IO purposes, it needs to remain empty
}
//_____________________________________________________________________________
AliAnalysisTaskMyTask::AliAnalysisTaskMyTask(const char* name) : AliAnalysisTaskSE(name),
fESD(0), fOutputList(0), fHistPt(0), fHistAvgPz(0), fHistMass(0)
fESD(0), fOutputList(0), fHistPt(0), fHistAvgPz(0), fHistAvgPt(0), fHistMass(0)
{
// constructor
DefineInput(0, TChain::Class()); // define the input of the analysis: in this case we take a 'chain' of events
......@@ -96,6 +98,10 @@ void AliAnalysisTaskMyTask::UserCreateOutputObjects()
fHistAvgPz = new TH1F("fHistAvgPz", "fHistAvgPz", 100, 0, 10); // create histogram
fOutputList->Add(fHistAvgPz);
// <Pt> histogram: value of average Pt (or Pt per track) for each event
fHistAvgPt = new TH1F("fHistAvgPt", "fHistAvgPt", 100, 0, 10); // create histogram
fOutputList->Add(fHistAvgPt);
// my mass histogram
Double_t fHistMassEdges[12] = {0.0,0.0005,0.0405,0.08,0.12,0.13,0.17,0.48,0.52,0.92,0.96,1.0}; // 11 bins =>> has 11+1 = 12 edges
......@@ -155,6 +161,8 @@ void AliAnalysisTaskMyTask::export_to_our_ESD_textual_format (Int_t selectedEven
Double_t PzSum = 0;
Double_t absPzSum = 0;
Double_t PtSum = 0;
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
......@@ -166,18 +174,20 @@ void AliAnalysisTaskMyTask::export_to_our_ESD_textual_format (Int_t selectedEven
Double_t Px = track->Px();
Double_t Py = track->Py();
Double_t Pt = track->Pt(); // transversal momentum, in case we need it
Double_t Pt = track->Pt(); // transversal momentum
Double_t Pz = track->Pz();
PzSum += Pz/iTracks; // Pz sum for |<Pz>| histogram
absPzSum += abs(Pz)/iTracks; //Remember: in C++, abs function overloads
PtSum += Pt/iTracks; // Pt sum for <Pt> histogram
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;
esd_detail << Px << " " << Py << " " << Pz << " " << Pt << endl;
fHistPt->Fill(Pt); // plot the pt value of the track in a histogram
......@@ -189,11 +199,22 @@ void AliAnalysisTaskMyTask::export_to_our_ESD_textual_format (Int_t selectedEven
fHistAvgPz->Fill(abs(PzSum));
}
if(PtSum != 0) { // This will only fill <Pt> histogram for events with tracks (non-empty)
fHistAvgPt->Fill(abs(PtSum));
}
if(selectedEventID == 0) {
// Pz:
highAvgPzEvent = 0;
lowAvgPzEvent = 0;
highAvgPz = PzSum;
lowAvgPz = PzSum;
// Pt:
highAvgPtEvent = 0;
highAvgPt = PtSum;
} else {
if(PzSum>highAvgPz) {
......@@ -205,6 +226,11 @@ void AliAnalysisTaskMyTask::export_to_our_ESD_textual_format (Int_t selectedEven
lowAvgPzEvent = selectedEventID;
}
if(PtSum>highAvgPt) {
highAvgPt = PtSum;
highAvgPtEvent = selectedEventID;
}
}
}
......@@ -237,6 +263,9 @@ void AliAnalysisTaskMyTask::Terminate(Option_t *)
// terminate
// called at the END of the analysis (when all events are processed)
cout << endl << endl << "Lowest Pz Mean (<Pz>) = " << lowAvgPz << " at Event " << lowAvgPzEvent;
cout << endl << "Highest Pz Mean (<Pz>) = " << highAvgPz << " at Event " << highAvgPzEvent << endl << endl;
cout << endl << "Highest Pz Mean (<Pz>) = " << highAvgPz << " at Event " << highAvgPzEvent << endl;
cout << endl << "Highest Pt Mean (<Pt>) = " << highAvgPt << " at Event " << highAvgPtEvent << endl << endl;
}
//_____________________________________________________________________________
......@@ -24,6 +24,7 @@ class AliAnalysisTaskMyTask : public AliAnalysisTaskSE
TList* fOutputList; //! output list
TH1F* fHistPt; //! Pt histogram
TH1F* fHistAvgPz; //! |<Pz>| histogram
TH1F* fHistAvgPt; //! <Pt> histogram
TH1F* fHistMass; //! my particle histogram!! :D
void export_to_our_ESD_textual_format (Int_t selectedEventID);
......
......@@ -2,7 +2,7 @@
# animate_particles.py - Animate HEP events
#
# For console only rendering (example):
# $ 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 -transparency=1.2 -stamp_note="Texto no canto" -its=1 -tpc=0 -trd=1 -emcal=0
# $ 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 -transparency=1.2 -stamp_note="Texto no canto" -its=1 -tpc=0 -trd=1 -emcal=0 -blendersave=0
#
import os
......@@ -40,6 +40,7 @@ parser.add_argument('-its','--its')
parser.add_argument('-tpc','--tpc')
parser.add_argument('-trd','--trd')
parser.add_argument('-emcal','--emcal')
parser.add_argument('-blendersave','--blendersave')
args = parser.parse_args()
bpy.context.user_preferences.view.show_splash = False
......@@ -56,7 +57,9 @@ fps = int(args.fps)
resolution_percent = int(args.resolution_percent)
stamp_note = args.stamp_note
transp_par = float(args.transp_par)
datafile = str(args.datafile)
detectors = [int(args.its),int(args.tpc),int(args.trd),int(args.emcal)] # Array that stores which detectors to build
blendersave = int(args.blendersave) # 1 (save Blender file) or 0 (don't)
#configure output
outputPath = "/tmp/blender/"
......@@ -65,7 +68,7 @@ fileIdentifier = "PhysicalTrajectories_"
renderCamera= args.render_camera
renderAnimation = True # True
saveBlenderFile = False # False
saveBlenderFile = blendersave # False
"""
# Create and configure animation driver
......@@ -75,7 +78,7 @@ driver.configure(renderCamera, duration, fps, simulated_t, outputPath, fileIdent
"""
# Create and configure animation driver
driver = dataDriver("AlirootFileGenerator",n_event,args.datafile) # Simple dataDriver
driver = dataDriver("AlirootFileGenerator",n_event,datafile) # Simple dataDriver
driver.configure(renderCamera, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent)
### Build scene
......@@ -90,7 +93,7 @@ animate_tracks(blender_tracks,particles,driver)
bpy.context.scene.frame_current = 24
## Save blender file
if saveBlenderFile: bpy.ops.wm.save_as_mainfile(filepath=outputPath+fileIdentifier+".blend")
if saveBlenderFile: bpy.ops.wm.save_as_mainfile(filepath=outputPath+fileIdentifier+"AlirootFileGenerator_"+datafile+"_Event_"+n_event+"_"+renderCamera+".blend")
# Render animation
if renderAnimation: driver.render()
......
......@@ -223,8 +223,8 @@ def addALICE_Geometry(bright_colors=True, transp_par=1.0, detectors=[1,1,1,1]):
def addLamps():
bpy.ops.object.lamp_add(type='POINT', location=(0,0,15))
bpy.ops.object.lamp_add(type='POINT', location=(0,0,-15))
bpy.ops.object.lamp_add(type='POINT', location=(4,1,6))
bpy.ops.object.lamp_add(type='POINT', location=(-4,-1,-6))
......@@ -258,11 +258,11 @@ def createSceneParticles(particles, createTracks = False):
clWhite = (255, 255, 255)
particle_colors = {"Electron":clRed, "Pion":clGreen, "Muon":clBlue, "Proton":clMagenta, "Kaon": clYellow, "Unknown": clWhite}
#Create Materials
# Create Materials
for type in particle_types:
bpy.data.materials.new(name=type)
#bpy.context.object.active_material = (1, 0, 0)
bpy.data.materials[type].emit = 0.1
bpy.data.materials[type].emit = 0.05
bpy.data.materials[type].diffuse_color = particle_colors[type]
bpy.data.materials[type].use_shadows = False
bpy.data.materials[type].use_cast_shadows = False
......
......@@ -34,7 +34,7 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
fi
OPTIONS=c:hdau:m:n:t:r:
LONGOPTS=camera:,resolution:,fps:,transparency:,duration:,maxparticles:,minparticles:,numberofevents:,minavgpz:,help,download,sample,url:,its,tpc,trd,emcal
LONGOPTS=camera:,resolution:,fps:,transparency:,duration:,maxparticles:,minparticles:,numberofevents:,minavgpz:,minavgpt:,help,download,sample,url:,its,tpc,trd,emcal,blendersave
# -regarding ! and PIPESTATUS see above
# -temporarily store output to be able to check for errors
......@@ -61,6 +61,7 @@ MAX_PARTICLES=1000
MIN_PARTICLES=0
N_OF_EVENTS=10
MIN_AVG_PZ=0
MIN_AVG_PT=0
HELP=false
DOWNLOAD=false
SAMPLE=false
......@@ -69,6 +70,7 @@ ITS=1 # 1 means "build this detector", while 0 means "don't"
TPC=1
TRD=1
EMCAL=1
BLENDERSAVE=0
# now enjoy the options in order and nicely split until we see --
while true; do
case "$1" in
......@@ -105,6 +107,10 @@ while true; do
MIN_AVG_PZ="$2"
shift 2
;;
--minavgpt)
MIN_AVG_PT="$2"
shift 2
;;
-t|--duration)
DURATION="$2"
shift 2
......@@ -141,6 +147,10 @@ while true; do
EMCAL=0
shift
;;
--blendersave)
BLENDERSAVE=1
shift
;;
--)
shift
break
......@@ -181,6 +191,10 @@ Usage:
Get only events for which its absolute value of average momentum in
the z direction is greater than or equal to VALUE. Useful for animating
events with 'boosts' of particles to the same side.
--minavgpt VALUE
Get only events for which its average transversal momentum is
greater than or equal to VALUE. Useful for animating events with
'boosts' of particles on the xy plane.
-t | --duration VALUE
Set the animation duration in seconds.
-r | --resolution VALUE
......@@ -205,6 +219,8 @@ Usage:
Removes TRD detector from animation
--emcal
Removes EMCal detector from animation
--blendersave
Saves Blender file along with animation clip
Example:
--------
......@@ -234,6 +250,7 @@ else
echo "Min particles: ${MIN_PARTICLES}"
echo "Number of events: ${N_OF_EVENTS}"
echo "Min Average Z Momentum: ${MIN_AVG_PZ}"
echo "Min Average Transversal Momentum: ${MIN_AVG_PT}"
echo "Camera: $CAMERA"
echo "-----------------------------------"
echo "------------ Detectors ------------"
......@@ -298,7 +315,7 @@ if [ "$SAMPLE" = "true" ]; then
pushd ${BLENDER_SCRIPT_DIR}
for type in $CAMERA; do
echo "Preparing sample animation with $type in Blender"
blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=${DURATION} -camera=${type} -datafile="d-esd-detail.dat" -simulated_t=0.03 -fps=${FPS} -resolution=${RESOLUTION} -transparency=${TRANSPARENCY} -stamp_note="opendata.cern.ch_record_1102_alice_2010_LHC10h_000139038_ESD_0001_2" -its=${ITS} -tpc=${TPC} -trd=${TRD} -emcal=${EMCAL}
blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=${DURATION} -camera=${type} -datafile="d-esd-detail.dat" -simulated_t=0.03 -fps=${FPS} -resolution=${RESOLUTION} -transparency=${TRANSPARENCY} -stamp_note="opendata.cern.ch_record_1102_alice_2010_LHC10h_000139038_ESD_0001_2" -its=${ITS} -tpc=${TPC} -trd=${TRD} -emcal=${EMCAL} -blendersave=${BLENDERSAVE}
done
popd
BLENDER_OUTPUT=.
......@@ -381,51 +398,64 @@ elif [ "$SAMPLE" = "false" ]; then
AVERAGE_PZ=$(awk 'BEGIN {pzsum=0;n=0} {pzsum+=$8;n++} END {print sqrt(pzsum*pzsum/n/n)}' ${BLENDER_SCRIPT_DIR}/${LOCAL_FILE_WITH_DATA})
echo "File $LOCAL_FILE_WITH_DATA has $NUMBER_OF_PARTICLES particles and average Z momentum $AVERAGE_PZ"
AVERAGE_PT=$(awk 'BEGIN {ptsum=0;n=0} {ptsum+=$9;n++} END {print ptsum/n}' ${BLENDER_SCRIPT_DIR}/${LOCAL_FILE_WITH_DATA})
if (( $(echo "$AVERAGE_PZ >= $MIN_AVG_PZ" |bc -l) )); then
if [[ $NUMBER_OF_PARTICLES -le $MAX_PARTICLES && $NUMBER_OF_PARTICLES -ge $MIN_PARTICLES && $EVENT_COUNTER -lt $N_OF_EVENTS ]]; then
echo "File $LOCAL_FILE_WITH_DATA has $NUMBER_OF_PARTICLES particles."
echo "Average Z momentum: $AVERAGE_PZ"
echo "Average transversal momentum $AVERAGE_PT"
# Increment event counter
EVENT_COUNTER=$EVENT_COUNTER+1
if (( $(echo "$AVERAGE_PT >= $MIN_AVG_PT" |bc -l) )); then
if (( $(echo "$AVERAGE_PZ >= $MIN_AVG_PZ" |bc -l) )); then
if [[ $NUMBER_OF_PARTICLES -le $MAX_PARTICLES && $NUMBER_OF_PARTICLES -ge $MIN_PARTICLES && $EVENT_COUNTER -lt $N_OF_EVENTS ]]; then
echo "Processing ${EVENT_UNIQUE_ID} ($NUMBER_OF_PARTICLES tracks) in Blender"
# Increment event counter
EVENT_COUNTER=$EVENT_COUNTER+1
pushd ${BLENDER_SCRIPT_DIR}
echo "Processing ${EVENT_UNIQUE_ID} ($NUMBER_OF_PARTICLES tracks) in Blender"
for type in $CAMERA; do
echo "Processing ${EVENT_UNIQUE_ID} with $type in Blender"
pushd ${BLENDER_SCRIPT_DIR}
blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=${DURATION} -camera=${type} -datafile="${LOCAL_FILE_WITH_DATA}" -n_event=${EVENT_ID} -simulated_t=0.03 -fps=${FPS} -resolution=${RESOLUTION} -transparency=${TRANSPARENCY} -stamp_note="${EVENT_UNIQUE_ID}" -its=${ITS} -tpc=${TPC} -trd=${TRD} -emcal=${EMCAL}
# Move generated file to final location
mv /tmp/blender/* ${BLENDER_OUTPUT}
echo "${type} for event ${EVENT_UNIQUE_ID} done."
done
for type in $CAMERA; do
echo "Processing ${EVENT_UNIQUE_ID} with $type in Blender"
# Move processed file to final location
mv $LOCAL_FILE_WITH_DATA ${BLENDER_OUTPUT}/$LOCAL_FILE_WITH_DATA
blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=${DURATION} -camera=${type} -datafile="${LOCAL_FILE_WITH_DATA}" -n_event=${EVENT_ID} -simulated_t=0.03 -fps=${FPS} -resolution=${RESOLUTION} -transparency=${TRANSPARENCY} -stamp_note="${EVENT_UNIQUE_ID}" -its=${ITS} -tpc=${TPC} -trd=${TRD} -emcal=${EMCAL} -blendersave=${BLENDERSAVE}
# Move generated file to final location
mv /tmp/blender/* ${BLENDER_OUTPUT}
echo "${type} for event ${EVENT_UNIQUE_ID} done."
done
popd
echo "EVENT ${EVENT_UNIQUE_ID} DONE with FILE $LOCAL_FILE_WITH_DATA."
else
# Move processed file to final location
mv $LOCAL_FILE_WITH_DATA ${BLENDER_OUTPUT}/$LOCAL_FILE_WITH_DATA
if [[ $NUMBER_OF_PARTICLES -lt $MIN_PARTICLES ]]; then
echo "Too little particles (minimum accepted is $MIN_PARTICLES). Continue."
elif [[ $NUMBER_OF_PARTICLES -gt $MAX_PARTICLES ]]; then
echo "Too many particles (maximum accepted is $MAX_PARTICLES). Continue."
elif [[ $EVENT_COUNTER -ge $N_OF_EVENTS ]]; then
echo "Numbers of events set to be animated has already been reached. Continue."
popd
echo "EVENT ${EVENT_UNIQUE_ID} DONE with FILE $LOCAL_FILE_WITH_DATA."
else
if [[ $NUMBER_OF_PARTICLES -lt $MIN_PARTICLES ]]; then
echo "Too little particles (minimum accepted is $MIN_PARTICLES). Continue."
elif [[ $NUMBER_OF_PARTICLES -gt $MAX_PARTICLES ]]; then
echo "Too many particles (maximum accepted is $MAX_PARTICLES). Continue."
elif [[ $EVENT_COUNTER -ge $N_OF_EVENTS ]]; then
echo "Numbers of events set to be animated has already been reached. Continue."
fi
# Remove non-processed files
pushd ${BLENDER_SCRIPT_DIR}
rm $LOCAL_FILE_WITH_DATA
popd
continue
fi
else
echo "Average Z Momentum too low (minimum accepted is $MIN_AVG_PZ). Continue."
# Remove non-processed files
pushd ${BLENDER_SCRIPT_DIR}
rm $LOCAL_FILE_WITH_DATA
popd
continue
fi
else
echo "Average Z Momentum too low (minimum accepted is $MIN_AVG_PZ). Continue."
echo "Average Transversal Momentum too low (minimum accepted is $MIN_AVG_PT). Continue."
# Remove non-processed files
pushd ${BLENDER_SCRIPT_DIR}
......
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