-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyptd2root.cpp
764 lines (715 loc) · 29.5 KB
/
myptd2root.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
// - Implementation of MyPTD2Root
// Example on access to data in 'brio' files from flsimulate:
// Uses the 'PTD' data bank
// 1) Access all available data in PTD data banks
// 2) Write data to a flat TTree ROOT file
// Ourselves
#include "myptd2root.h"
#include <mctools/simulated_data.h>
// Standard Library
// Third Party
// - A
// This Project
// Macro which automatically implements the interface needed
// to enable the module to be loaded at runtime
// The first argument is the typename
// The second is the string key used to access the module in pipeline
// scripts. This must be globally unique.
DPP_MODULE_REGISTRATION_IMPLEMENT(MyPTD2Root,"MyPTD2Root");
// Construct
MyPTD2Root::MyPTD2Root() : dpp::base_module()
{
filename_output_="default.root";
}
// Destruct
MyPTD2Root::~MyPTD2Root() {
// MUST reset module at destruction
this->reset();
}
// Initialize
void MyPTD2Root::initialize(const datatools::properties& myConfig,
datatools::service_manager& flServices,
dpp::module_handle_dict_type& /*moduleDict*/) {
// Throw logic exception if we've already initialized this instance
DT_THROW_IF(this->is_initialized(),
std::logic_error,
"MyPTD2Root already initialized");
// Extract the filename_out key from the supplied config, if
// the key exists. datatools::properties throws an exception if
// the key isn't in the config, so catch this if thrown and don't do
// anything
try {
myConfig.fetch("filename_out",this->filename_output_);
} catch (std::logic_error& e) {
}
// Look for services
if (flServices.has("geometry"))
{
const geomtools::geometry_service& GS = flServices.get<geomtools::geometry_service> ("geometry");
// initialize geometry manager
// std::cout << "Initialize geo manager " << std::endl;
geometry_manager_ = &GS.get_geom_manager();
DT_THROW_IF(!geometry_manager_,
std::runtime_error,
"Null pointer to geometry manager return by geometry_service");
}
std::cout << "In INIT: create TFile " << std::endl;
// Next all root file output here
hfile_ = new TFile(filename_output_.c_str(),"RECREATE","Output file of Simulation data");
hfile_->cd();
tree_ = new TTree("PTD","PTD");
tree_->SetDirectory(hfile_);
// header data
tree_->Branch("header.runnumber",&header_.runnumber_);
tree_->Branch("header.eventnumber",&header_.eventnumber_);
tree_->Branch("header.date",&header_.date_);
tree_->Branch("header.runtype",&header_.runtype_);
tree_->Branch("header.simulated",&header_.simulated_);
// generator data
tree_->Branch("truth.vertex_x",&gen_.vertex_x_);
tree_->Branch("truth.vertex_y",&gen_.vertex_y_);
tree_->Branch("truth.vertex_z",&gen_.vertex_z_);
// hit data
tree_->Branch("hits.nhits",&hits_.nofhits_);
// cluster data
tree_->Branch("clus.nclus",&clus_.nclus_);
tree_->Branch("clus.nclushits",&clus_.nclushits_);
tree_->Branch("clus.clus_nhits",&clus_.clus_nhits_);
// particle data
tree_->Branch("particle.nofparticles",&particle_.nofparticles_);
tree_->Branch("particle.nofgammaonly",&particle_.nofgammas_);
tree_->Branch("particle.particleID",&particle_.particle_id_);
tree_->Branch("particle.charge",&particle_.charge_);
tree_->Branch("particle.vertex1_type",&particle_.vertex1_type_);
tree_->Branch("particle.vertex1_x",&particle_.vertex1_x_);
tree_->Branch("particle.vertex1_y",&particle_.vertex1_y_);
tree_->Branch("particle.vertex1_z",&particle_.vertex1_z_);
tree_->Branch("particle.foil1_dir_x",&particle_.foil1_dir_x_);
tree_->Branch("particle.foil1_dir_y",&particle_.foil1_dir_y_);
tree_->Branch("particle.foil1_dir_z",&particle_.foil1_dir_z_);
tree_->Branch("particle.vertex2_type",&particle_.vertex2_type_);
tree_->Branch("particle.vertex2_x",&particle_.vertex2_x_);
tree_->Branch("particle.vertex2_y",&particle_.vertex2_y_);
tree_->Branch("particle.vertex2_z",&particle_.vertex2_z_);
tree_->Branch("particle.foil2_dir_x",&particle_.foil2_dir_x_);
tree_->Branch("particle.foil2_dir_y",&particle_.foil2_dir_y_);
tree_->Branch("particle.foil2_dir_z",&particle_.foil2_dir_z_);
tree_->Branch("particle.traj_length",&particle_.traj_length_);
tree_->Branch("particle.traj_cl_del",&particle_.traj_cluster_delayed_);
tree_->Branch("particle.traj_cl_del_time",&particle_.traj_cluster_delayed_time_);
tree_->Branch("particle.calo1_associated",&particle_.calo1_associated_);
tree_->Branch("particle.calo1_type",&particle_.calo1_type_);
tree_->Branch("particle.calo1_energy",&particle_.calo1_energy_);
tree_->Branch("particle.calo1_sigma_energy",&particle_.calo1_sigma_energy_);
tree_->Branch("particle.calo1_time",&particle_.calo1_time_);
tree_->Branch("particle.calo1_sigma_time",&particle_.calo1_sigma_time_);
tree_->Branch("particle.calo1_side",&particle_.calo1_side_);
tree_->Branch("particle.calo1_column",&particle_.calo1_column_);
tree_->Branch("particle.calo1_row",&particle_.calo1_row_);
tree_->Branch("particle.calo1_wall",&particle_.calo1_wall_);
tree_->Branch("particle.calo1_loc_x",&particle_.calo1_loc_x_);
tree_->Branch("particle.calo1_loc_y",&particle_.calo1_loc_y_);
tree_->Branch("particle.calo1_loc_z",&particle_.calo1_loc_z_);
tree_->Branch("particle.calo2_associated",&particle_.calo2_associated_);
tree_->Branch("particle.calo2_type",&particle_.calo2_type_);
tree_->Branch("particle.calo2_energy",&particle_.calo2_energy_);
tree_->Branch("particle.calo2_sigma_energy",&particle_.calo2_sigma_energy_);
tree_->Branch("particle.calo2_time",&particle_.calo2_time_);
tree_->Branch("particle.calo2_sigma_time",&particle_.calo2_sigma_time_);
tree_->Branch("particle.calo2_side",&particle_.calo2_side_);
tree_->Branch("particle.calo2_column",&particle_.calo2_column_);
tree_->Branch("particle.calo2_row",&particle_.calo2_row_);
tree_->Branch("particle.calo2_wall",&particle_.calo2_wall_);
tree_->Branch("particle.calo2_loc_x",&particle_.calo2_loc_x_);
tree_->Branch("particle.calo2_loc_y",&particle_.calo2_loc_y_);
tree_->Branch("particle.calo2_loc_z",&particle_.calo2_loc_z_);
this->_set_initialized(true);
}
// Process
dpp::base_module::process_status MyPTD2Root::process(datatools::things& workItem) {
// Local variables
// particle event data
std::vector<int> particleid;
std::vector<int> charge;
std::vector<int> vertex1type;
std::vector<double> vertex1_x;
std::vector<double> vertex1_y;
std::vector<double> vertex1_z;
std::vector<double> foil1_dir_x;
std::vector<double> foil1_dir_y;
std::vector<double> foil1_dir_z;
std::vector<int> vertex2type;
std::vector<double> vertex2_x;
std::vector<double> vertex2_y;
std::vector<double> vertex2_z;
std::vector<double> foil2_dir_x;
std::vector<double> foil2_dir_y;
std::vector<double> foil2_dir_z;
std::vector<double> traj_length;
std::vector<int> traj_cl_delayed;
std::vector<double> traj_cl_delayed_time;
std::vector<int> calo1associated;
std::vector<int> calo1type;
std::vector<double> calo1energy;
std::vector<double> calo1sigmaenergy;
std::vector<double> calo1time;
std::vector<double> calo1sigmatime;
std::vector<int> calo1side;
std::vector<int> calo1column;
std::vector<int> calo1row;
std::vector<int> calo1wall;
std::vector<double> calo1_loc_x;
std::vector<double> calo1_loc_y;
std::vector<double> calo1_loc_z;
std::vector<int> calo2associated;
std::vector<int> calo2type;
std::vector<double> calo2energy;
std::vector<double> calo2sigmaenergy;
std::vector<double> calo2time;
std::vector<double> calo2sigmatime;
std::vector<int> calo2side;
std::vector<int> calo2column;
std::vector<int> calo2row;
std::vector<int> calo2wall;
std::vector<double> calo2_loc_x;
std::vector<double> calo2_loc_y;
std::vector<double> calo2_loc_z;
std::vector<int> clus_nhits;
// Access the workItem
// look for hits
if(workItem.has("CD")) {
const snemo::datamodel::calibrated_data & CD = workItem.get<snemo::datamodel::calibrated_data>("CD");
hits_.nofhits_ = CD.calibrated_tracker_hits().size();
}
else {
hits_.nofhits_ = 0;
}
// look for clusters
if(workItem.has("TCD")) {
const snemo::datamodel::tracker_clustering_data & TCD = workItem.get<snemo::datamodel::tracker_clustering_data>("TCD");
clus_.nclushits_ = 0;
clus_.nclus_ = 0;
if(TCD.has_default_solution()) {
clus_.nclus_ = TCD.get_default_solution().get_clusters().size();
for(const datatools::handle<snemo::datamodel::tracker_cluster>& i : TCD.get_default_solution().get_clusters()) {
int nh = i.get().get_number_of_hits();
clus_nhits.push_back(nh);
clus_.nclushits_ += nh;
}
}
}
else {
clus_.nclus_ = 0;
clus_.nclushits_ = 0;
}
clus_.clus_nhits_ = &clus_nhits;
// look for reconstructed data
if(workItem.has("PTD"))
{
const snemo::datamodel::particle_track_data & PTD = workItem.get<snemo::datamodel::particle_track_data>("PTD");
// Extract particle track data
if (PTD.has_particles()) {
particle_.nofparticles_ = PTD.get_number_of_particles();
for (size_t i=0; i<PTD.get_number_of_particles();++i) {
const snemo::datamodel::particle_track & the_particle = PTD.get_particle(i);
particleid.push_back(the_particle.get_track_id());
charge.push_back(the_particle.get_charge());
// first the vertices
if (the_particle.has_vertices()) {
unsigned int i = 0;
if (i<the_particle.get_vertices().size()) {
const geomtools::blur_spot & vertex = the_particle.get_vertices().at(i).get();
const geomtools::vector_3d & translation = vertex.get_placement().get_translation();
vertex1_x.push_back(translation.x());
vertex1_y.push_back(translation.y());
vertex1_z.push_back(translation.z());
if (vertex.has_geom_id()) { // vertex is on calorimeter (calo or xcalo or gveto)
vertex1type.push_back(vertex.get_geom_id().get_type());
foil1_dir_x.push_back(0.);
foil1_dir_y.push_back(0.);
foil1_dir_z.push_back(0.);
}
else if (translation.x() < 0.01 && translation.x() > -0.01) { // test for zero x foil coordinate
vertex1type.push_back(0);
// get the line direction at the foil vertex position
if (the_particle.has_trajectory()) {
const snemo::datamodel::tracker_trajectory & the_trajectory = the_particle.get_trajectory();
const snemo::datamodel::base_trajectory_pattern & the_base_pattern = the_trajectory.get_pattern();
if (the_base_pattern.get_pattern_id()=="line") {
const geomtools::line_3d & the_shape = (const geomtools::line_3d&)the_base_pattern.get_shape();
geomtools::vector_3d direction = the_shape.get_direction_on_curve(the_shape.get_first());
foil1_dir_x.push_back(direction.x());
foil1_dir_y.push_back(direction.y());
foil1_dir_z.push_back(direction.z());
}
else {
const geomtools::helix_3d & the_shape = (const geomtools::helix_3d&)the_base_pattern.get_shape();
geomtools::vector_3d direction = the_shape.get_direction_on_curve(the_shape.get_first());
foil1_dir_x.push_back(direction.x());
foil1_dir_y.push_back(direction.y());
foil1_dir_z.push_back(direction.z());
}
}
else {
foil1_dir_x.push_back(0.);
foil1_dir_y.push_back(0.);
foil1_dir_z.push_back(0.);
}
}
else {// vertex is on wire (i.e. neither calo, nor foil)
vertex1type.push_back(1);
foil1_dir_x.push_back(0.);
foil1_dir_y.push_back(0.);
foil1_dir_z.push_back(0.);
}
}
else {
vertex1type.push_back(-1);
vertex1_x.push_back(0.);
vertex1_y.push_back(0.);
vertex1_z.push_back(0.);
foil1_dir_x.push_back(0.);
foil1_dir_y.push_back(0.);
foil1_dir_z.push_back(0.);
}
i = 1;
if (i<the_particle.get_vertices().size()) {
const geomtools::blur_spot & vertex = the_particle.get_vertices().at(i).get();
const geomtools::vector_3d & translation = vertex.get_placement().get_translation();
vertex2_x.push_back(translation.x());
vertex2_y.push_back(translation.y());
vertex2_z.push_back(translation.z());
if (vertex.has_geom_id()) { // vertex is on calorimeter (calo or xcalo or gveto)
vertex2type.push_back(vertex.get_geom_id().get_type());
foil2_dir_x.push_back(0.);
foil2_dir_y.push_back(0.);
foil2_dir_z.push_back(0.);
}
else if (translation.x() < 0.01 && translation.x() > -0.01) { // test for zero x foil coordinate
vertex2type.push_back(0);
// get the line direction at the foil vertex position
if (the_particle.has_trajectory()) {
const snemo::datamodel::tracker_trajectory & the_trajectory = the_particle.get_trajectory();
const snemo::datamodel::base_trajectory_pattern & the_base_pattern = the_trajectory.get_pattern();
if (the_base_pattern.get_pattern_id()=="line") {
const geomtools::line_3d & the_shape = (const geomtools::line_3d&)the_base_pattern.get_shape();
geomtools::vector_3d direction = the_shape.get_direction_on_curve(the_shape.get_first());
foil2_dir_x.push_back(direction.x());
foil2_dir_y.push_back(direction.y());
foil2_dir_z.push_back(direction.z());
}
else {
const geomtools::helix_3d & the_shape = (const geomtools::helix_3d&)the_base_pattern.get_shape();
geomtools::vector_3d direction = the_shape.get_direction_on_curve(the_shape.get_first());
foil2_dir_x.push_back(direction.x());
foil2_dir_y.push_back(direction.y());
foil2_dir_z.push_back(direction.z());
}
}
else {
foil2_dir_x.push_back(0.);
foil2_dir_y.push_back(0.);
foil2_dir_z.push_back(0.);
}
}
else {// vertex is on wire (i.e. neither calo, nor foil)
vertex2type.push_back(1);
foil2_dir_x.push_back(0.);
foil2_dir_y.push_back(0.);
foil2_dir_z.push_back(0.);
}
}
else {
vertex2type.push_back(-1);
vertex2_x.push_back(0.);
vertex2_y.push_back(0.);
vertex2_z.push_back(0.);
foil2_dir_x.push_back(0.);
foil2_dir_y.push_back(0.);
foil2_dir_z.push_back(0.);
}
}
else {
vertex1type.push_back(-1);
vertex1_x.push_back(0.);
vertex1_y.push_back(0.);
vertex1_z.push_back(0.);
foil1_dir_x.push_back(0.);
foil1_dir_y.push_back(0.);
foil1_dir_z.push_back(0.);
vertex2type.push_back(-1);
vertex2_x.push_back(0.);
vertex2_y.push_back(0.);
vertex2_z.push_back(0.);
foil2_dir_x.push_back(0.);
foil2_dir_y.push_back(0.);
foil2_dir_z.push_back(0.);
}
// then associated calorimeter hits
if (the_particle.has_associated_calorimeter_hits()) {
unsigned int i = 0;
if (i<the_particle.get_associated_calorimeter_hits().size()) {
const snemo::datamodel::calibrated_calorimeter_hit & calo_hit = the_particle.get_associated_calorimeter_hits().at(i).get();
const geomtools::mapping & the_mapping = geometry_manager_->get_mapping();
if (! the_mapping.validate_id(calo_hit.get_geom_id())) {
std::vector<geomtools::geom_id> gids;
the_mapping.compute_matching_geom_id(calo_hit.get_geom_id(), gids); // front calo block = last entry
const geomtools::geom_info & info = the_mapping.get_geom_info(gids.back()); // in vector gids
const geomtools::vector_3d & loc = info.get_world_placement().get_translation();
calo1_loc_x.push_back(loc.x());
calo1_loc_y.push_back(loc.y());
calo1_loc_z.push_back(loc.z());
}
else {
const geomtools::geom_info & info = the_mapping.get_geom_info(calo_hit.get_geom_id());
const geomtools::vector_3d & loc = info.get_world_placement().get_translation();
calo1_loc_x.push_back(loc.x());
calo1_loc_y.push_back(loc.y());
calo1_loc_z.push_back(loc.z());
}
calo1associated.push_back(1);
calo1energy.push_back(calo_hit.get_energy());
calo1sigmaenergy.push_back(calo_hit.get_sigma_energy());
calo1time.push_back(calo_hit.get_time());
calo1sigmatime.push_back(calo_hit.get_sigma_time());
calo1type.push_back(calo_hit.get_geom_id().get_type());
if (calo_hit.get_geom_id ().get_type () == 1302)
{
// CALO
calo1side.push_back(calo_hit.get_geom_id().get(1));
calo1column.push_back(calo_hit.get_geom_id().get(2));
calo1row.push_back(calo_hit.get_geom_id().get(3));
calo1wall.push_back(-1);
}
else if (calo_hit.get_geom_id ().get_type () == 1232)
{
// XCALO
calo1side.push_back(calo_hit.get_geom_id().get(1));
calo1column.push_back(calo_hit.get_geom_id().get(3));
calo1wall.push_back(calo_hit.get_geom_id().get(2));
calo1row.push_back(calo_hit.get_geom_id().get(0));
}
else if (calo_hit.get_geom_id ().get_type () == 1252)
{
// GVETO
calo1side.push_back(calo_hit.get_geom_id().get(1));
calo1column.push_back(calo_hit.get_geom_id().get(3));
calo1wall.push_back(calo_hit.get_geom_id().get(2));
calo1row.push_back(-1);
}
else {
calo1side.push_back(-1);
calo1column.push_back(-1);
calo1wall.push_back(-1);
calo1row.push_back(-1);
}
}
else {
calo1associated.push_back(-1); // non particle
calo1energy.push_back(-1.0);
calo1sigmaenergy.push_back(-1.0);
calo1time.push_back(-1.0);
calo1sigmatime.push_back(-1.0);
calo1type.push_back(-1);
calo1side.push_back(-1);
calo1column.push_back(-1);
calo1wall.push_back(-1);
calo1row.push_back(-1);
calo1_loc_x.push_back(1.0e3);
calo1_loc_y.push_back(1.0e4);
calo1_loc_z.push_back(1.0e4);
}
i = 1;
if (i<the_particle.get_associated_calorimeter_hits().size()) {
const snemo::datamodel::calibrated_calorimeter_hit & calo_hit = the_particle.get_associated_calorimeter_hits().at(i).get();
const geomtools::mapping & the_mapping = geometry_manager_->get_mapping();
if (! the_mapping.validate_id(calo_hit.get_geom_id())) {
std::vector<geomtools::geom_id> gids;
the_mapping.compute_matching_geom_id(calo_hit.get_geom_id(), gids); // front calo block = last entry
const geomtools::geom_info & info = the_mapping.get_geom_info(gids.back()); // in vector gids
const geomtools::vector_3d & loc = info.get_world_placement().get_translation();
calo2_loc_x.push_back(loc.x());
calo2_loc_y.push_back(loc.y());
calo2_loc_z.push_back(loc.z());
}
else {
const geomtools::geom_info & info = the_mapping.get_geom_info(calo_hit.get_geom_id());
const geomtools::vector_3d & loc = info.get_world_placement().get_translation();
calo2_loc_x.push_back(loc.x());
calo2_loc_y.push_back(loc.y());
calo2_loc_z.push_back(loc.z());
}
calo2associated.push_back(1);
calo2energy.push_back(calo_hit.get_energy());
calo2sigmaenergy.push_back(calo_hit.get_sigma_energy());
calo2time.push_back(calo_hit.get_time());
calo2sigmatime.push_back(calo_hit.get_sigma_time());
calo2type.push_back(calo_hit.get_geom_id().get_type());
if (calo_hit.get_geom_id ().get_type () == 1302)
{
// CALO
calo2side.push_back(calo_hit.get_geom_id().get(1));
calo2column.push_back(calo_hit.get_geom_id().get(2));
calo2row.push_back(calo_hit.get_geom_id().get(3));
calo2wall.push_back(-1);
}
else if (calo_hit.get_geom_id ().get_type () == 1232)
{
// XCALO
calo2side.push_back(calo_hit.get_geom_id().get(1));
calo2column.push_back(calo_hit.get_geom_id().get(3));
calo2wall.push_back(calo_hit.get_geom_id().get(2));
calo2row.push_back(calo_hit.get_geom_id().get(0));
}
else if (calo_hit.get_geom_id ().get_type () == 1252)
{
// GVETO
calo2side.push_back(calo_hit.get_geom_id().get(1));
calo2column.push_back(calo_hit.get_geom_id().get(3));
calo2wall.push_back(calo_hit.get_geom_id().get(2));
calo2row.push_back(-1);
}
else {
calo2side.push_back(-1);
calo2column.push_back(-1);
calo2wall.push_back(-1);
calo2row.push_back(-1);
}
}
else {
calo2associated.push_back(-1); // non particle
calo2energy.push_back(-1.0);
calo2sigmaenergy.push_back(-1.0);
calo2time.push_back(-1.0);
calo2sigmatime.push_back(-1.0);
calo2type.push_back(-1);
calo2side.push_back(-1);
calo2column.push_back(-1);
calo2wall.push_back(-1);
calo2row.push_back(-1);
calo2_loc_x.push_back(1.0e3);
calo2_loc_y.push_back(1.0e4);
calo2_loc_z.push_back(1.0e4);
}
}
else { // not a calo vertex, fill blanks
calo1associated.push_back(-1); // non particle
calo1energy.push_back(-1.0);
calo1sigmaenergy.push_back(-1.0);
calo1time.push_back(-1.0);
calo1sigmatime.push_back(-1.0);
calo1type.push_back(-1);
calo1side.push_back(-1);
calo1column.push_back(-1);
calo1wall.push_back(-1);
calo1row.push_back(-1);
calo1_loc_x.push_back(1.0e3);
calo1_loc_y.push_back(1.0e4);
calo1_loc_z.push_back(1.0e4);
calo2associated.push_back(-1); // non particle
calo2energy.push_back(-1.0);
calo2sigmaenergy.push_back(-1.0);
calo2time.push_back(-1.0);
calo2sigmatime.push_back(-1.0);
calo2type.push_back(-1);
calo2side.push_back(-1);
calo2column.push_back(-1);
calo2wall.push_back(-1);
calo2row.push_back(-1);
calo2_loc_x.push_back(1.0e3);
calo2_loc_y.push_back(1.0e4);
calo2_loc_z.push_back(1.0e4);
}
// then the trajectory length, always
if (the_particle.has_trajectory()) {
const snemo::datamodel::tracker_trajectory & the_trajectory = the_particle.get_trajectory();
const snemo::datamodel::base_trajectory_pattern & the_base_pattern = the_trajectory.get_pattern();
const geomtools::i_shape_1d & the_shape = the_base_pattern.get_shape();
traj_length.push_back(the_shape.get_length());
const snemo::datamodel::tracker_cluster & the_cluster = the_trajectory.get_cluster();
traj_cl_delayed.push_back((int)the_cluster.is_delayed());
if (the_cluster.is_delayed()>0)
traj_cl_delayed_time.push_back(the_cluster.get_hit(0).get_delayed_time());
else
traj_cl_delayed_time.push_back(-1.0);
}
else {
traj_length.push_back(-1.0);
traj_cl_delayed.push_back(-1);
traj_cl_delayed_time.push_back(-1.0);
}
}
}
else
particle_.nofparticles_ = 0;
// Extract un-associated calorimeter hits
if (PTD.has_non_associated_calorimeters ()) {
particle_.nofgammas_ = PTD.get_non_associated_calorimeters().size();
for (unsigned int i=0; i<PTD.get_non_associated_calorimeters().size();++i) {
const snemo::datamodel::calibrated_calorimeter_hit & un_calo_hit = PTD.get_non_associated_calorimeters().at(i).get();
const geomtools::mapping & the_mapping = geometry_manager_->get_mapping();
if (! the_mapping.validate_id(un_calo_hit.get_geom_id())) {
std::vector<geomtools::geom_id> gids;
the_mapping.compute_matching_geom_id(un_calo_hit.get_geom_id(), gids); // front calo block = last entry
const geomtools::geom_info & info = the_mapping.get_geom_info(gids.back()); // in vector gids
const geomtools::vector_3d & loc = info.get_world_placement().get_translation();
calo1_loc_x.push_back(loc.x());
calo1_loc_y.push_back(loc.y());
calo1_loc_z.push_back(loc.z());
}
else {
const geomtools::geom_info & info = the_mapping.get_geom_info(un_calo_hit.get_geom_id());
const geomtools::vector_3d & loc = info.get_world_placement().get_translation();
calo1_loc_x.push_back(loc.x());
calo1_loc_y.push_back(loc.y());
calo1_loc_z.push_back(loc.z());
}
calo1associated.push_back(0);
calo1energy.push_back(un_calo_hit.get_energy());
calo1sigmaenergy.push_back(un_calo_hit.get_sigma_energy());
calo1time.push_back(un_calo_hit.get_time());
calo1sigmatime.push_back(un_calo_hit.get_sigma_time());
calo1type.push_back(un_calo_hit.get_geom_id().get_type());
if (un_calo_hit.get_geom_id ().get_type () == 1302)
{
// CALO
calo1side.push_back(un_calo_hit.get_geom_id().get(1));
calo1column.push_back(un_calo_hit.get_geom_id().get(2));
calo1row.push_back(un_calo_hit.get_geom_id().get(3));
calo1wall.push_back(-1);
}
else if (un_calo_hit.get_geom_id ().get_type () == 1232)
{
// XCALO
calo1side.push_back(un_calo_hit.get_geom_id().get(1));
calo1column.push_back(un_calo_hit.get_geom_id().get(3));
calo1wall.push_back(un_calo_hit.get_geom_id().get(2));
calo1row.push_back(un_calo_hit.get_geom_id().get(0));
}
else if (un_calo_hit.get_geom_id ().get_type () == 1252)
{
// GVETO
calo1side.push_back(un_calo_hit.get_geom_id().get(1));
calo1column.push_back(un_calo_hit.get_geom_id().get(3));
calo1wall.push_back(un_calo_hit.get_geom_id().get(2));
calo1row.push_back(-1);
}
else {
}
// calo unassociated, append blanks
particleid.push_back(-1); // not a particle
charge.push_back(-1);
vertex1_x.push_back(0.); // calo only
vertex1_y.push_back(0.);
vertex1_z.push_back(0.);
foil1_dir_x.push_back(0.); // double fill for vertex
foil1_dir_y.push_back(0.);
foil1_dir_z.push_back(0.);
vertex1type.push_back(-1);
vertex2_x.push_back(0.); // calo only
vertex2_y.push_back(0.);
vertex2_z.push_back(0.);
foil2_dir_x.push_back(0.); // double fill for vertex
foil2_dir_y.push_back(0.);
foil2_dir_z.push_back(0.);
vertex2type.push_back(-1);
traj_length.push_back(-1.0);
traj_cl_delayed.push_back(-1);
traj_cl_delayed_time.push_back(-1.0);
calo2associated.push_back(-1); // non particle
calo2energy.push_back(-1.0);
calo2sigmaenergy.push_back(-1.0);
calo2time.push_back(-1.0);
calo2sigmatime.push_back(-1.0);
calo2type.push_back(-1);
calo2side.push_back(-1);
calo2column.push_back(-1);
calo2wall.push_back(-1);
calo2row.push_back(-1);
calo2_loc_x.push_back(1.0e3);
calo2_loc_y.push_back(1.0e4);
calo2_loc_z.push_back(1.0e4);
}
}
else {
particle_.nofgammas_ = 0;
}
}
particle_.particle_id_ = &particleid;
particle_.charge_ = &charge;
particle_.vertex1_type_ = &vertex1type;
particle_.vertex1_x_ = &vertex1_x;
particle_.vertex1_y_ = &vertex1_y;
particle_.vertex1_z_ = &vertex1_z;
particle_.foil1_dir_x_ = &foil1_dir_x;
particle_.foil1_dir_y_ = &foil1_dir_y;
particle_.foil1_dir_z_ = &foil1_dir_z;
particle_.vertex2_type_ = &vertex2type;
particle_.vertex2_x_ = &vertex2_x;
particle_.vertex2_y_ = &vertex2_y;
particle_.vertex2_z_ = &vertex2_z;
particle_.foil2_dir_x_ = &foil2_dir_x;
particle_.foil2_dir_y_ = &foil2_dir_y;
particle_.foil2_dir_z_ = &foil2_dir_z;
particle_.traj_length_ = &traj_length;
particle_.traj_cluster_delayed_ = &traj_cl_delayed;
particle_.traj_cluster_delayed_time_ = &traj_cl_delayed_time;
particle_.calo1_associated_ = &calo1associated;
particle_.calo1_type_ = &calo1type;
particle_.calo1_energy_ = &calo1energy;
particle_.calo1_sigma_energy_ = &calo1sigmaenergy;
particle_.calo1_time_ = &calo1time;
particle_.calo1_sigma_time_ = &calo1sigmatime;
particle_.calo1_side_ = &calo1side;
particle_.calo1_column_ = &calo1column;
particle_.calo1_row_ = &calo1row;
particle_.calo1_wall_ = &calo1wall;
particle_.calo1_loc_x_ = &calo1_loc_x;
particle_.calo1_loc_y_ = &calo1_loc_y;
particle_.calo1_loc_z_ = &calo1_loc_z;
particle_.calo2_associated_ = &calo2associated;
particle_.calo2_type_ = &calo2type;
particle_.calo2_energy_ = &calo2energy;
particle_.calo2_sigma_energy_ = &calo2sigmaenergy;
particle_.calo2_time_ = &calo2time;
particle_.calo2_sigma_time_ = &calo2sigmatime;
particle_.calo2_side_ = &calo2side;
particle_.calo2_column_ = &calo2column;
particle_.calo2_row_ = &calo2row;
particle_.calo2_wall_ = &calo2wall;
particle_.calo2_loc_x_ = &calo2_loc_x;
particle_.calo2_loc_y_ = &calo2_loc_y;
particle_.calo2_loc_z_ = &calo2_loc_z;
// look for event header
if(workItem.has("EH"))
{
const snemo::datamodel::event_header & EH = workItem.get<snemo::datamodel::event_header>("EH");
// std::cout << "In process: found EH event header " << std::endl;
header_.runnumber_ = EH.get_id ().get_run_number ();
header_.eventnumber_ = EH.get_id ().get_event_number ();
header_.date_ = 0;
header_.runtype_ = 0;
header_.simulated_ = (EH.is_simulated () ? true : false);
}
if(workItem.has("SD")) {
const mctools::simulated_data& SD = workItem.get<mctools::simulated_data>("SD");
gen_.vertex_x_ = SD.get_vertex().x();
gen_.vertex_y_ = SD.get_vertex().y();
gen_.vertex_z_ = SD.get_vertex().z();
}
tree_->Fill();
// MUST return a status, see ref dpp::processing_status_flags_type
return dpp::base_module::PROCESS_OK;
}
// Reset
void MyPTD2Root::reset() {
// write the output, finished streaming
hfile_->cd();
tree_->Write();
hfile_->Close(); //
std::cout << "In reset: finished conversion, file closed " << std::endl;
// clean up
delete hfile_;
filename_output_ = "default.root";
this->_set_initialized(false);
}