13 #include "GaudiKernel/NTuple.h"
14 #include "GaudiKernel/INTupleSvc.h"
15 #include "GaudiKernel/SmartDataPtr.h"
18 #include "CLHEP/GenericFunctions/FixedConstant.hh"
21 #include "HepPDT/ParticleDataTable.hh"
22 #include "HepPDT/ParticleData.hh"
23 #include "GaudiKernel/IPartPropSvc.h"
30 #include "CaloDetDescr/CaloDetDescrElement.h"
36 #include "CLHEP/Units/PhysicalConstants.h"
40 #include "GaudiKernel/ITHistSvc.h"
45 #include <sys/types.h>
49 #include <sys/times.h>
53 using HepGeom::Point3D;
54 using CLHEP::HepLorentzVector;
59 inline int iabs (
int a) {
return (
a>=0)?
a : -
a;}
63 static const int ticksPerJiffy = sysconf(_SC_CLK_TCK)/100;
66 cpuTime=(
buff.tms_utime +
buff.tms_stime +
buff.tms_cutime +
buff.tms_cstime)/ticksPerJiffy;
83 NTuple::Item<double>
eta;
84 NTuple::Item<double>
pt;
85 NTuple::Item<double>
phi;
88 NTuple::Item<double>
x;
89 NTuple::Item<double>
y;
90 NTuple::Item<double>
z;
122 if (
m_c!=
nullptr){
delete m_c;
m_c=
nullptr; }
126 std::string
names[162] = {
"eta",
"pt",
"phi",
"pos_x",
"pos_y",
"pos_z",
127 "emb0_cell",
"emb1_cell",
"emb2_cell",
"emb3_cell",
"emec0_cell",
"emec1_cell",
"emec2_cell",
"emec3_cell",
128 "hec0_cell",
"hec1_cell",
"hec2_cell",
"hec3_cell",
"fc1_cell",
"fc2_cell",
"fc3_cell",
129 "emb0_hits",
"emb1_hits",
"emb2_hits",
"emb3_hits",
"emec0_hits",
"emec1_hits",
"emec2_hits",
"emec3_hits",
130 "hec0_hits",
"hec1_hits",
"hec2_hits",
"hec3_hits",
"fc1_hits",
"fc2_hits",
"fc3_hits",
131 "emb0_sumE",
"emb1_sumE",
"emb2_sumE",
"emb3_sumE",
"emec0_sumE",
"emec1_sumE",
"emec2_sumE",
"emec3_sumE",
132 "hec0_sumE",
"hec1_sumE",
"hec2_sumE",
"hec3_sumE",
"fc1_sumE",
"fc2_sumE",
"fc3_sumE",
133 "emb0_dPhi",
"emb1_dPhi",
"emb2_dPhi",
"emb3_dPhi",
"emec0_dPhi",
"emec1_dPhi",
"emec2_dPhi",
"emec3_dPhi",
134 "hec0_dPhi",
"hec1_dPhi",
"hec2_dPhi",
"hec3_dPhi",
"fc1_dX",
"fc2_dX",
"fc3_dX",
135 "emb0_sPhi",
"emb1_sPhi",
"emb2_sPhi",
"emb3_sPhi",
"emec0_sPhi",
"emec1_sPhi",
"emec2_sPhi",
"emec3_sPhi",
136 "hec0_sPhi",
"hec1_sPhi",
"hec2_sPhi",
"hec3_sPhi",
"fc1_sX",
"fc2_sX",
"fc3_sX",
137 "emb0_dEta",
"emb1_dEta",
"emb2_dEta",
"emb3_dEta",
"emec0_dEta",
"emec1_dEta",
"emec2_dEta",
"emec3_dEta",
138 "hec0_dEta",
"hec1_dEta",
"hec2_dEta",
"hec3_dEta",
"fc1_dY",
"fc2_dY",
"fc3_dY",
139 "emb0_sEta",
"emb1_sEta",
"emb2_sEta",
"emb3_sEta",
"emec0_sEta",
"emec1_sEta",
"emec2_sEta",
"emec3_sEta",
140 "hec0_sEta",
"hec1_sEta",
"hec2_sEta",
"hec3_sEta",
"fc1_sY",
"fc2_sY",
"fc3_sY",
141 "emb0_time",
"emb1_time",
"emb2_time",
"emb3_time",
"emec0_time",
"emec1_time",
"emec2_time",
"emec3_time",
142 "hec0_time",
"hec1_time",
"hec2_time",
"hec3_time",
"fc1_time",
"fc2_time",
"fc3_time",
143 "emb0_widthX",
"emb1_widthX",
"emb2_widthX",
"emb3_widthX",
"emec0_widthX",
"emec1_widthX",
"emec2_widthX",
"emec3_widthX",
144 "hec0_widthX",
"hec1_widthX",
"hec2_widthX",
"hec3_widthX",
"fc1_widthX",
"fc2_widthX",
"fc3_widthX",
145 "emb0_widthY",
"emb1_widthY",
"emb2_widthY",
"emb3_widthY",
"emec0_widthY",
"emec1_widthY",
"emec2_widthY",
"emec3_widthY",
146 "hec0_widthY",
"hec1_widthY",
"hec2_widthY",
"hec3_widthY",
"fc1_widthY",
"fc2_widthY",
"fc3_widthY",
147 "cpuTime",
"Energy",
"PDG_ID",
"RunNo",
"EventNo",
"E_Dep" };
149 double lim[162][2] = { {0,5}, {0,100}, {-4,4}, {-1600,1600}, {-1600,1600}, {-4000,4000},
150 {0,0.25}, {0,3}, {0,6}, {0,0.1}, {0,0.25}, {0,2}, {0,3}, {0,0.1}, {0,1}, {0,10}, {0,10}, {0,10}, {0,0.1}, {0,0.1}, {0,0.1},
151 {0,100}, {0,600}, {0,600}, {0,50}, {0,50}, {0,400}, {0,500}, {0,200}, {0,100}, {0,1000}, {0,1000}, {0,100}, {0,150}, {0,50}, {0,10},
152 {0,0.4}, {0,5}, {0,10}, {0,0.2}, {0,0.1}, {0,3}, {0,5}, {0,0.2}, {0,1}, {0,10}, {0,10}, {0,0.1}, {0,1}, {0,0.1}, {0,0.1},
153 {-500,500}, {-100,100}, {-15,15}, {-200,200}, {-3000,3000}, {-60,60}, {-25,25}, {-200,200}, {-50,50}, {-50,50}, {-50,50}, {-50,50}, {-60,60}, {-500,500}, {-200,200},
154 {0,1000}, {0,500}, {0,200}, {0,500}, {0,2000}, {0,250}, {0,300}, {0,500}, {0,200}, {0,200}, {0,200}, {0,200}, {0,100}, {0,100}, {0,50},
155 {-150,150}, {-15,15}, {-20,20}, {-200,200}, {-0,2500}, {-50,20}, {-15,15}, {-150,150}, {-50,50}, {-50,50}, {-50,50}, {-50,50}, {-60,60}, {-500,500}, {-200,200},
156 {0,500}, {0,100}, {0,100}, {0,400}, {0,1000}, {0,150}, {0,100}, {0,400}, {0,200}, {0,200}, {0,200}, {0,200}, {0,60}, {0,100}, {0,50},
157 {0,750}, {0,25}, {0,20}, {0,1000}, {0,10000}, {0,40}, {0,30}, {0,1000}, {0,1000}, {0,100}, {0,100}, {0,200}, {0,10}, {0,500}, {0,100},
158 {-150,150}, {-15,15}, {-20,20}, {-200,200}, {-0,2500}, {-50,20}, {-15,15}, {-150,150}, {-50,50}, {-50,50}, {-50,50}, {-50,50}, {-60,60}, {-500,500}, {-200,200},
159 {-150,150}, {-15,15}, {-20,20}, {-200,200}, {-0,2500}, {-50,20}, {-15,15}, {-150,150}, {-50,50}, {-50,50}, {-50,50}, {-50,50}, {-60,60}, {-500,500}, {-200,200},
160 {0,50}, {0,100}, {-25,25}, {0,10}, {0,1000}, {0,10}};
179 for (
int i=0;
i<162;
i++){
184 ATH_MSG_WARNING(
"Failed to register historam " <<
names[
i] <<
". Not sure what will happen now..." );
190 if (!
file)
throw std::runtime_error (
"Ntuple MGR not open");
191 NTuple::Directory *
col=
ntupleSvc()->createDirectory(
"/NTUPLES/FILE/COL");
192 NTuplePtr
nt(
ntupleSvc(),
"/NTUPLES/FILE/COL/SingleTrackValidation");
193 if (!
nt)
nt=
ntupleSvc()->book(
col, 1, CLID_ColumnWiseTuple,
"SingleTrackValidation");
195 if (
nt->addItem(
"Eta",
m_c->
eta ).isFailure() ||
196 nt->addItem(
"Pt",
m_c->
pt ).isFailure() ||
197 nt->addItem(
"BarrelX",
m_c->
x ).isFailure() ||
198 nt->addItem(
"BarrelY",
m_c->
y ).isFailure() ||
199 nt->addItem(
"BarrelZ",
m_c->
z ).isFailure() ||
200 nt->addItem(
"Phi",
m_c->
phi ).isFailure() ){
201 ATH_MSG_WARNING(
"Registration of some of the ntuple branches failed. No idea what will happen next..." );
210 for (
int i=0;
i<15;
i++){
211 if (
i<12) sprintf(
title,
"S%i_C00",
i);
212 else sprintf(
title,
"FC%i_C00",
i-11);
214 if (
i<12) sprintf(
title,
"S%i_SumE",
i);
215 else sprintf(
title,
"FC%i_SumE",
i-11);
217 if (
i<12) sprintf(
title,
"S%i_Hits",
i);
218 else sprintf(
title,
"FC%i_Hits",
i-11);
220 if (
i<12) sprintf(
title,
"S%i_DeltaPhi",
i);
221 else sprintf(
title,
"FC%i_DeltaX",
i-11);
223 if (
i<12) sprintf(
title,
"S%i_SigmaPhi",
i);
224 else sprintf(
title,
"FC%i_SigmaX",
i-11);
226 if (
i<12) sprintf(
title,
"S%i_DeltaEta",
i);
227 else sprintf(
title,
"FC%i_DeltaY",
i-11);
229 if (
i<12) sprintf(
title,
"S%i_SigmaEta",
i);
230 else sprintf(
title,
"FC%i_SigmaY",
i-11);
232 if (
i<12) sprintf(
title,
"S%i_Time",
i);
233 else sprintf(
title,
"FC%i_Time",
i-11);
235 if (
i<12) sprintf(
title,
"S%i_WidthX",
i);
236 else sprintf(
title,
"FC%i_WidthX",
i-11);
238 if (
i<12) sprintf(
title,
"S%i_WidthY",
i);
239 else sprintf(
title,
"FC%i_WidthY",
i-11);
244 nt->addItem(
"TrackEnergy" ,
m_c->
Energy ).isFailure() ||
245 nt->addItem(
"ParticleID" ,
m_c->
PDG ).isFailure() ||
246 nt->addItem(
"Run#" ,
m_c->
RunNo ).isFailure() ||
249 ATH_MSG_WARNING(
"Registration of some of the ntuple branches failed. No idea what will happen next..." );
259 return StatusCode::SUCCESS;
274 sc=service(
"StoreGateSvc", stg);
276 const EventContext& context = getContext();
277 int RunNum=context.eventID().run_number();
278 int EvtNum=context.eventID().event_number();
279 double RunStr=
double(RunNum);
280 double EvtStr=
double(EvtNum);
290 if (fieldCondObj ==
nullptr) {
292 return StatusCode::FAILURE;
294 fieldCondObj->getInitializedCache (fieldCache);
299 if (
sc.isFailure())
return StatusCode::SUCCESS;
300 for (
const HepMC::GenEvent*
e : *mcEvent) {
306 const HepPDT::ParticleDataTable * dataTable =
m_c->
partPropSvc->PDT();
307 const HepPDT::ParticleData * particleData = dataTable->particle(
iabs(theParticle->pdg_id()));
310 HepLorentzVector
momentum(theParticle->momentum().px(),
311 theParticle->momentum().py(),
312 theParticle->momentum().pz(),
313 theParticle->momentum().e());
314 Point3D<double> origin(theParticle->production_vertex()->position().x(),
315 theParticle->production_vertex()->position().y(),
316 theParticle->production_vertex()->position().z());
317 double charge = theParticle->pdg_id() > 0 ? particleData->charge() : - particleData->charge();
319 m_c->
phi = theParticle->momentum().phi();
320 m_c->
eta = -
log(
tan(theParticle->momentum().theta()/2));
322 m_c->
pt = theParticle->momentum().perp();
323 int partID = theParticle->pdg_id();
326 m_c->
Energy = theParticle->momentum().e();
327 m_histos[2]->Fill( theParticle->momentum().phi() );
328 double myEta = -
log(
tan(theParticle->momentum().theta()/2));
329 if (!finite(myEta))
m_histos[0]->Fill(0);
346 bool hitsBarrel=
false;
348 for (
double t = 0;
t< 50;
t += 0.1) {
349 x = extrapolator.
x()(
t);
350 y = extrapolator.
y()(
t);
351 z = extrapolator.
z()(
t);
352 double magicZ=3640.0*
mm;
353 double magicR=1500.0*
mm;
354 if (
x*
x+
y*
y > magicR*magicR) {
361 else if (
z*
z > magicZ*magicZ) {
376 double radImpact = std::sqrt(
x*
x+
y*
y+
z*
z);
377 double phiImpact = std::atan2(
y,
x);
378 double thetaImpact = std::acos(
z/radImpact);
386 for (
int i=0;
i<4;
i++) {
391 std::cerr <<
"SingleTrackValidation EXCEPTION (LAREM)" <<
e.message() << std::endl;
394 for (
int i=0;
i<4;
i++) {
399 std::cerr <<
"SingleTrackValidation EXCEPTION (LAREM)" <<
e.message() << std::endl;
402 for (
int i=0;
i<4;
i++) {
407 std::cerr <<
"SingleTrackValidation EXCEPTION in (LARHEC)" <<
e.message() << std::endl;
410 for (
int i=1;
i<4;
i++) {
415 std::cerr <<
"SingleTrackValidation EXCEPTIONin LARFCAL" <<
e.message() << std::endl;
421 for (
int z=0;
z<15;
z++){
426 std::string lArKey = hitsBarrel ?
"LArHitEMB" :
"LArHitEMEC" ;
428 double eSum [15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
429 double eEta [15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
430 double eEtaEta [15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
431 double ePhi [15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
432 double ePhiPhi [15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
433 int hit_count [15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
434 double eX [15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
435 double eXX [15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
436 double eY [15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
437 double eYY [15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
438 double c00 [15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
439 double t00 [15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
443 for (
int i=0;
i<4;
i++) {
458 if (
status==StatusCode::SUCCESS) {
460 for (hi = (*iter).begin();hi != (*iter).end(); ++hi){
461 const LArHit* larHit = *hi;
467 for (
int j=0;j<15;j++) {
468 if (hitElement==element[j]) {
473 if (lArKey==
"LArHitEMEC") samplingLayer += 4;
474 else if (lArKey==
"LArHitHEC") samplingLayer += 8;
475 else if (lArKey==
"LArHitFCAL") samplingLayer += 11;
480 double hitPhi = hitElement->
phi() - phiImpact;
481 if (hitPhi < -
pi) hitPhi +=
twopi;
482 if (hitPhi >
pi) hitPhi -=
twopi;
484 eSum [samplingLayer]+=
energy;
485 eEta [samplingLayer]+=
energy*hitElement->
eta();
486 eEtaEta [samplingLayer]+=
energy*hitElement->
eta()*hitElement->
eta();
487 ePhi [samplingLayer]+=
energy*hitPhi;
488 ePhiPhi [samplingLayer]+=
energy*hitPhi*hitPhi;
489 eX [samplingLayer]+=
energy*hitElement->
x();
490 eXX [samplingLayer]+=
energy*hitElement->
x()*hitElement->
x();
491 eY [samplingLayer]+=
energy*hitElement->
y();
492 eYY [samplingLayer]+=
energy*hitElement->
y()*hitElement->
y();
494 hit_count[samplingLayer]+=1;
499 for (
int i=0;
i<15;
i++) {
500 if (eSum[
i]!=0) eEta[
i] /= eSum[
i];
501 if (eSum[
i]!=0) eEtaEta[
i] /= eSum[
i];
502 if (eSum[
i]!=0) ePhi[
i] /= eSum[
i];
503 if (eSum[
i]!=0) ePhiPhi[
i] /= eSum[
i];
504 if (eSum[
i]!=0) eY[
i] /= eSum[
i];
505 if (eSum[
i]!=0) eYY[
i] /= eSum[
i];
506 if (eSum[
i]!=0) eX[
i] /= eSum[
i];
507 if (eSum[
i]!=0) eXX[
i] /= eSum[
i];
508 if (eSum[
i]!=0) t00[
i] /= eSum[
i];
512 double dThetaDEta = -1.0/cosh(etaImpact);
516 for (
int z=0;
z<15;
z++){
525 m_c->
s_sigmaEta[
z]=radImpact*std::fabs(dThetaDEta)*std::sqrt(eEtaEta[
z]- eEta[
z]*eEta[
z]);
537 for (
int i=0;
i<15;
i++){
547 m_histos[81+
i]->Fill( radImpact*dThetaDEta*(eEta[
i]-etaImpact) );
548 m_histos[96+
i]->Fill( radImpact*std::fabs(dThetaDEta)*std::sqrt(eEtaEta[
i]-eEta[
i]*eEta[
i]) );
563 return StatusCode::SUCCESS;
568 return StatusCode::SUCCESS;