Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 266 → Rev 267

/belle2/masterclass/index.php
12,6 → 12,21
<script src="js/belle2_gen.js"></script>
<script src="js/workspace.js"></script>
<script src="js/FileSaver.min.js"></script>
 
<style>
table {
border-collapse: collapse;
width: 100%;
}
 
th, td {
padding: 0px;
text-align: right;
}
 
tr:hover{background-color:#ffffff}
</style>
 
<script src="js/Blob.js"></script>
 
/belle2/masterclass/js/belle2_def.js
11,6 → 11,9
.setAlign(Blockly.ALIGN_RIGHT)
.appendField("2. Particle");
this.appendDummyInput()
.appendField("Same particle lists?")
.appendField(new Blockly.FieldDropdown([["No", "0"], ["Yes", "1"]]), "sameparticles");
this.appendDummyInput()
.appendField("New Particle")
.appendField(new Blockly.FieldDropdown([["electron", "ELECTRON"], ["muon", "MUON"], ["pion", "PION"], ["kaon", "KAON"], ["proton", "PROTON"], ["photon", "PHOTON"], ["Ks", "KS"], ["D", "D"], ["D*", "DSTAR"], ["J/Psi", "JPSI"]]), "simplepid");
this.appendDummyInput()
27,7 → 30,7
this.setInputsInline(false);
this.setOutput(true, "particle list");
this.setColour(120);
this.setTooltip('');
this.setTooltip('Combine two particles in the new particle by making combinations between particles in two input lists');
this.setHelpUrl('http://www.example.com/');
}
};
51,7 → 54,7
this.setInputsInline(false);
this.setOutput(true, "particle list");
this.setColour(65);
this.setTooltip('');
this.setTooltip('Create a new list of particles based on the original particle list or any input particle list');
this.setHelpUrl('http://www.example.com/');
}
};
82,7 → 85,7
this.setInputsInline(true);
this.setOutput(true, "histogram");
this.setColour(20);
this.setTooltip('');
this.setTooltip('This block handles the histogram creation and filling. Define a number of bins, minimum and maximum of the range and assign a variable to plot');
this.setHelpUrl('http://www.example.com/');
}
};
95,13 → 98,19
.appendField("Number of events: ")
.appendField(new Blockly.FieldNumber(5000, 0), "neve");
this.appendDummyInput()
.appendField("First event: ")
.appendField(new Blockly.FieldNumber(0, 0), "first");
this.appendDummyInput()
.appendField("Data Source")
.appendField(new Blockly.FieldDropdown([["hadron-1", "1"], ["hadron-2", "2"]]), "datasource");
this.appendDummyInput()
.appendField("Print particle list?")
.appendField(new Blockly.FieldDropdown([["No", "0"], ["Yes", "1"]]), "print");
this.appendValueInput("list")
.setCheck("particle list")
.appendField("Particle List");
this.setColour(230);
this.setTooltip('');
this.setTooltip('Run the analysis, specify data source, number of events, first event and a list of particles to process.');
this.setHelpUrl('http://www.example.com/');
}
};
130,7 → 139,7
this.setInputsInline(true);
this.setOutput(true, "particle list");
this.setColour(180);
this.setTooltip('');
this.setTooltip('Create a list of primary particles, if not used, the primary particles are used in the empty particle list connectors');
this.setHelpUrl('http://www.example.com/');
}
};
/belle2/masterclass/js/belle2_gen.js
4,12 → 4,13
var value_list2 = Blockly.JavaScript.valueToCode(block, 'list2', Blockly.JavaScript.ORDER_ATOMIC);
if (value_list2.length==0) value_list2='""';
var dropdown_simplepid = block.getFieldValue('simplepid');
var dropdown_sameparticles = block.getFieldValue('sameparticles');
var number_mass0 = block.getFieldValue('mass0');
var number_mass1 = block.getFieldValue('mass1');
var value_histogram = Blockly.JavaScript.valueToCode(block, 'histogram', Blockly.JavaScript.ORDER_ATOMIC);
if (value_histogram.length==0) value_histogram='""';
// TODO: Assemble JavaScript into code variable.
var code = '{"combiner":{"list1":' + value_list1 + ',"list2":' + value_list2 + ',"pid":"' + dropdown_simplepid + '","m0":"' + number_mass0 + '","m1":"' + number_mass1 + '","histogram":' + value_histogram + '}}\n';
var code = '{"combiner":{"list1":' + value_list1 + ',"list2":' + value_list2 + ',"sameparticles":"'+ dropdown_sameparticles +'","pid":"' + dropdown_simplepid + '","m0":"' + number_mass0 + '","m1":"' + number_mass1 + '","histogram":' + value_histogram + '}}\n';
// TODO: Change ORDER_NONE to the correct strength.
return [code, Blockly.JavaScript.ORDER_NONE];
};
42,11 → 43,14
 
Blockly.JavaScript['simple_analysis'] = function(block) {
var number_neve = block.getFieldValue('neve');
var number_first= block.getFieldValue('first');
var number_print= block.getFieldValue('print');
var dropdown_datasource = block.getFieldValue('datasource');
var value_list = Blockly.JavaScript.valueToCode(block, 'list', Blockly.JavaScript.ORDER_ATOMIC);
if (value_list.length==0) value_list='""';
// TODO: Assemble JavaScript into code variable.
var code = '{"analysis":{"neve":"' + number_neve + '","datasource":"' + dropdown_datasource + '","list":' + value_list + '}}\n';
var code = '{"analysis":{"neve":"' + number_neve + '","first":"' + number_first + '","print":"' + number_print + '","datasource":"' + dropdown_datasource + '","list":' + value_list + '}}\n';
return code;
};
 
66,4 → 70,4
var code = '{"primary":' + '{"histogram":' + value_histogram + '}}\n';
// TODO: Change ORDER_NONE to the correct strength.
return [code, Blockly.JavaScript.ORDER_NONE];
};
};
/belle2/masterclass/js/belle2_gen_mod.js
52,10 → 52,11
 
Blockly.JavaScript['simple_analysis'] = function(block) {
var number_neve = block.getFieldValue('neve');
var number_first = block.getFieldValue('first');
var dropdown_datasource = block.getFieldValue('datasource');
var value_list = Blockly.JavaScript.valueToCode(block, 'list', Blockly.JavaScript.ORDER_ATOMIC);
// TODO: Assemble JavaScript into code variable.
var code = 'simple_analysis(' + ' neve ' + number_neve + ' datasource ' + dropdown_datasource + ' list ' + value_list + ')\n';
var code = 'simple_analysis(' + ' neve ' + number_neve ' + ' first ' + number_first + ' datasource ' + dropdown_datasource + ' list ' + value_list + ')\n';
//var code = '...';
return code;
};
75,4 → 76,4
//var code = '...';
// TODO: Change ORDER_NONE to the correct strength.
return [code, Blockly.JavaScript.ORDER_NONE];
};
};
/belle2/masterclass/runscript.php
178,6 → 178,8
$data = json_decode($code, true);
 
$neve = $data['analysis']['neve'];
$first = $data['analysis']['first'];
$evprint = $data['analysis']['print'];
$source= $data['analysis']['datasource'];
 
$xml = '<?xml version="1.0" encoding="utf-8"?>' . xmlWalker($data,'start');
197,6 → 199,10
 
$el = $dom->getElementsByTagName('neve')->item(0);
$fstart->appendChild($el);
$el = $dom->getElementsByTagName('first')->item(0);
$fstart->appendChild($el);
$el = $dom->getElementsByTagName('print')->item(0);
$fstart->appendChild($el);
$el = $dom->getElementsByTagName('datasource')->item(0);
$fstart->appendChild($el);
 
255,7 → 261,9
$nodelist = $fstart->getElementsByTagName('h1d');
$init = PHP_EOL . "void Blab2::Init(){" . PHP_EOL ;
$init .="fNeve=$neve;" . PHP_EOL ;
$init .="fNfirst=$first;" . PHP_EOL ;
$init .="fData=$source;" . PHP_EOL ;
$init .="fPrint=$evprint;" . PHP_EOL ;
foreach ($nodelist as $node) {
$init .= $node->nodeName . "(";
$cnt=0;
/belle2/masterclass/src/BParticle.cc
67,7 → 67,7
return nprt;
}
 
int CombineParticles(TClonesArray *plist1 ,TClonesArray *plist2 , float masslow, float massup, SIMPLEPID pid, TClonesArray *pout){
int CombineParticles(TClonesArray *plist1 ,TClonesArray *plist2 , int same, float masslow, float massup, SIMPLEPID pid, TClonesArray *pout){
// Loop over all the particles in both lists.
pout->Clear();
int nprt=0;
74,7 → 74,7
for(TIter next1(plist1);BParticle * p1 =(BParticle *) next1();) {
// the second loop
for(TIter next2(plist2); BParticle * p2 =(BParticle *) next2();) {
for( TIter next2 = (plist1!=plist2 && same==0) ? TIter(plist2): TIter(next1) ; BParticle * p2 =(BParticle *) next2();) {
BParticle p = *p1 + *p2; // Combine two particles into a new particle
if (p.InMassRange(masslow, massup)){
p.SetPid(pid);
/belle2/masterclass/src/BParticle.h
73,7 → 73,7
};
 
int SelectParticles(TClonesArray *pin , int charge, SIMPLEPID type, TClonesArray *pout);
int CombineParticles(TClonesArray *plist1 ,TClonesArray *plist2 , float masslow, float massup, SIMPLEPID pid, TClonesArray *pout);
int CombineParticles(TClonesArray *plist1 ,TClonesArray *plist2 , int same, float masslow, float massup, SIMPLEPID pid, TClonesArray *pout);
 
 
#endif
/belle2/masterclass/src/Blab2.cc
23,6 → 23,7
public:
UInt_t fNeve;
UInt_t fNfirst;
UInt_t fPrint;
int fData;
TH1F *fH[100];
UInt_t fHtype[100];
35,7 → 36,7
void Process();
void h1d(const char *varname, const char *name, int nbins, double min, double max, int id );
int selector(int pin, int charge, SIMPLEPID particlename, int hid, int pout );
int combiner(int id0 ,int id1 , SIMPLEPID particlename, double min, double max, int hid, int id );
int combiner(int id0 ,int id1 , int same, SIMPLEPID particlename, double min, double max, int hid, int id );
int fix_mass(int id);
int Fill(int hid, BParticle *p);
void plist(int i);
46,7 → 47,7
 
ClassImp(Blab2)
 
Blab2::Blab2():fNfirst(0), fNeve(0), fData(0){
Blab2::Blab2():fNfirst(0), fNeve(0), fData(0), fPrint(0) {
 
Process();
};
78,7 → 79,7
return 0;
}
 
int Blab2::combiner(int _p0, int _p1,SIMPLEPID pid, double min, double max, int hid, int _p2 ){
int Blab2::combiner(int _p0, int _p1,int same, SIMPLEPID pid, double min, double max, int hid, int _p2 ){
// Loop over all the particles in both lists.
if (_p0 < 0 ) _p0 =0;
if (_p1 < 0 ) _p1 =0;
89,13 → 90,12
for(TIter next1(fList[_p0]);BParticle * p1 =(BParticle *) next1();) {
// the second loop
for(TIter next2 = (_p0!=_p1) ? TIter(fList[_p1]): TIter(next1) ; BParticle * p2 =(BParticle *) next2();) {
if (p1==p2) continue;
// in the case the second parti
for(TIter next2 = (_p0!=_p1 && same==0) ? TIter(fList[_p1]): TIter(next1) ; BParticle * p2 =(BParticle *) next2();) {
if (p1==p2) continue; // do not use the same particle in the combinations
BParticle p = *p1 + *p2; // Combine two particles into a new particle
if (p.InMassRange(min, max)){
//SIMPLEPID pid = PION; // should be set to particlename
p.SetPid(pid);
p.SetPid(pid); // set PID to particlename to fix the particle mass
TClonesArray& list = *fList[_p2];
new (list[nprt++]) BParticle ( p ); // create a new entry in kslist list of particles
Fill(hid, &p);
152,6 → 152,7
 
void Blab2::Process(){
 
char sList[0xFFFF];
for (int i=0;i<100;i++) fH[i]=NULL;
for (int i=0;i<100;i++) fHtype[i]=0;
for (int i=0;i<100;i++) fList[i]=NULL;
165,14 → 166,14
TBranch * branch = t-> GetBranch( "BEvent"); // Obtain a branch for "BEvent" in the tree
branch-> SetAddress(&mevent); // Register created "BEvent" object to the branch
TH1F *fHnprt= new TH1F("h100", "Number of particles in the event;N particles;N events", 50, -0.5, 49.5);
TH1F *fHid= new TH1F("h101", "Particle type;ID;N particles", 6, -0, 6);
 
const char *names[6]={"PHOTON", "ELECTRON", "PION", "MUON", "KAON", "PROTON"};
TH1F *fHid= new TH1F("h101", "Particle types;ID;N particles", 6, -0, 6);
const char *names[12]={"PHOTON", "ELECTRON", "PION", "MUON", "KAON", "PROTON", "JPSI", "D", "DSTAR", "B","KS", "ALL" };
for (int i=1;i<=6;i++) fHid->GetXaxis()->SetBinLabel(i,names[i-1]);
 
send_message(0, TString::Format("Number of Entries in the file %lld\n", t->GetEntries() ),0);
send_message(0, TString::Format("<br>Number of Events in the file %lld<br>\n", t->GetEntries() ),0);
TStopwatch timer;
timer.Start();
int nev = 0;
int i =TMath::Min(fNfirst, (UInt_t) t-> GetEntries());
int cNeve=TMath::Min(fNfirst+fNeve, (UInt_t) t-> GetEntries());
while (i<cNeve){
181,15 → 182,23
event();
if (i%10000==0) send_message(2, TString::Format("Event %d\n",i), (100*i)/cNeve);
int progress = (100*i)/cNeve;
if (i%10000==0) send_message(2, TString::Format("Event %d\n",i), progress);
 
int nprt=0;
if (nev>100) fPrint = 0; // disable particle prints for huge numer of events
if (fPrint) sprintf(sList,"Primary particle list for Event %d<br/><table class='plist' ><tr><th>N<th>px(GeV/c)<th>py(GeV/c)<th>pz(GeV/c)<th>p(GeV/c)<th>Energy(GeV)<th>Charge<th>ID<th></tr>", i);
for(TIter next(fList[0]); BParticle * p =(BParticle *) next();) {
nprt++;
fHid->Fill(p->pid());
if (fPrint) sprintf(sList,"%s<tr><td>%d<td>%g<td>%g<td>%g<td>%g<td>%g<td>%1.0f<td>%s</tr>",sList,nprt, p->px(),p->py(),p->pz(),p->GetMomentum(),p->e(), p->charge(),names[p->pid()] );
}
fHnprt->Fill(nprt);
 
if (fPrint) {
sprintf(sList,"%s</table>",sList);
send_message(0, TString(sList),progress);
nev++;
}
mevent-> Clear(); // Clear the memory.
for (int k=0;k<100;k++) if (fList[k]!=0) fList[k]->Clear();
i++;