17 float getx(
float r,
float phi) {
20 float gety(
float r,
float phi) {
24 return sqrt(x*x + y*y);
31 if (x!=0) phi = atan2(y,x);
36 float deltax2 = (x1-x2)*(x1-x2);
37 float deltay2 = (y1-y2)*(y1-y2);
38 return sqrt(deltax2+deltay2);
43 #include <JANA/JApplication.h>
44 #include <JANA/JFactory.h>
91 gPARMS->SetDefaultParameter(
"BCCC:VERBOSE",
VERBOSE);
94 bcal_calib_cosmic_cdc_tree =
new TTree(
"bcal_calib_cosmic_cdc",
95 "tree of DBCALHit energies and the length of the track through each cell.");
96 bcal_calib_cosmic_cdc_tree->Branch(
"eventnum",&eventnum,
"eventnum/i");
97 bcal_calib_cosmic_cdc_tree->Branch(
"cell",&cell,
"cell/i");
99 bcal_calib_cosmic_cdc_tree->Branch(
"layer",&tlayer,
"layer/i");
100 bcal_calib_cosmic_cdc_tree->Branch(
"module",&tmodule,
"module/i");
101 bcal_calib_cosmic_cdc_tree->Branch(
"sector",&tsector,
"sector/i");
102 bcal_calib_cosmic_cdc_tree->Branch(
"globalsect",&tglobalsect,
"globalsect/i");
103 bcal_calib_cosmic_cdc_tree->Branch(
"numcells",&numcells,
"numcells/i");
104 bcal_calib_cosmic_cdc_tree->Branch(
"dist",&tdist,
"dist/f");
105 bcal_calib_cosmic_cdc_tree->Branch(
"use",&use,
"use/f");
106 bcal_calib_cosmic_cdc_tree->Branch(
"dse",&dse,
"dse/f");
107 bcal_calib_cosmic_cdc_tree->Branch(
"track_m",&track_m,
"track_m/f");
108 bcal_calib_cosmic_cdc_tree->Branch(
"track_c",&track_c,
"track_c/f");
109 bcal_calib_cosmic_cdc_tree->Branch(
"chisq",&chisq,
"chisq/f");
110 bcal_calib_cosmic_cdc_tree->Branch(
"Ndof",&Ndof,
"Ndof/i");
145 vector<const DBCALGeometry *> BCALGeomVec;
146 loop->Get(BCALGeomVec);
147 if(BCALGeomVec.size() == 0)
148 throw JException(
"Could not load DBCALGeometry object!");
149 auto dBCALGeom = BCALGeomVec[0];
153 vector<const DTrackCandidate*> CDCCOSMIC_vec;
154 loop->Get(CDCCOSMIC_vec,
"CDCCOSMIC");
155 unsigned int num_CDCCOSMIC = CDCCOSMIC_vec.size();
157 vector<int> CellId_vec;
158 vector<float> distance_vec;
160 if (num_CDCCOSMIC>0) {
165 chisq = CDCCOSMIC->
chisq;
166 Ndof = CDCCOSMIC->
Ndof;
169 track_m = cdcmom.y()/cdcmom.x();
170 track_c = cdcpos.y() - track_m*cdcpos.x();
172 printf(
"BCCC >> pos (%6.2f,%6.2f,%6.2f) mom (%6.2f,%6.2f,%6.2f) m=%6.2f, c=%6.2f, chisq=%6.2f, Ndof=%i\n",
173 cdcpos.x(), cdcpos.y(), cdcpos.z(), cdcmom.x(), cdcmom.y(), cdcmom.z(),track_m,track_c,chisq,Ndof);
175 float r[5], phi[2][5],
x[2][5],
y[2][5];
177 bcal_radii = dBCALGeom->GetBCAL_radii();
180 for (
int laybound=0; laybound<=4; laybound++) {
182 r[laybound] = dBCALGeom->bcal_radii[laybound];
184 float A = 1 + track_m*track_m;
185 float B = 2 * track_m * track_c;
186 float C = track_c*track_c - r[laybound]*r[laybound];
187 float disc = (B*B - 4*A*C);
189 x[0][laybound] = 0, y[0][laybound] = 0, x[1][laybound] = 0, y[1][laybound] = 0;
190 phi[0][laybound]=0 , phi[1][laybound]=0;
192 x[0][laybound] = (-B +
sqrt(disc))/(2*A);
193 x[1][laybound] = (-B -
sqrt(disc))/(2*A);
194 y[0][laybound] = track_m*x[0][laybound] + track_c;
195 y[1][laybound] = track_m*x[1][laybound] + track_c;
196 phi[0][laybound] =
getposphi(x[0][laybound],y[0][laybound]);
197 phi[1][laybound] =
getposphi(x[1][laybound],y[1][laybound]);
201 int fADC_cellId = dBCALGeom->fADCcellId_rphi( r[laybound], phi[
track][laybound]);
202 int module = dBCALGeom->module( fADC_cellId );
203 int layer = dBCALGeom->layer( fADC_cellId );
204 int sector = dBCALGeom->sector( fADC_cellId );
205 int glosector = dBCALGeom->getglobalsector(module,sector);
206 printf(
"BCCC >> intersection: boundary=%i (x,y)=(%6.2f,%6.2f) (r,phi)=(%6.2f,%6.3f) cellId 0x%4x (mod,lay,sec,glosec) = (%2i,%2i,%2i,%3i)\n",
207 laybound, x[
track][laybound], y[
track][laybound], r[laybound], phi[
track][laybound],
208 fADC_cellId, module, layer, sector, glosector);
223 float total_distance = 0;
228 int fADC_cellIdIN = dBCALGeom->fADCcellId_rphi( r[
layer], phi[
track][layer]);
229 int moduleIN = dBCALGeom->module( fADC_cellIdIN );
230 int sectorIN = dBCALGeom->sector( fADC_cellIdIN );
231 int globalsectorIN = dBCALGeom->getglobalsector(moduleIN,sectorIN);
232 int fADC_cellIdOUT = dBCALGeom->fADCcellId_rphi( r[layer+1], phi[
track][layer+1]);
233 int moduleOUT = dBCALGeom->module( fADC_cellIdOUT );
234 int sectorOUT = dBCALGeom->sector( fADC_cellIdOUT );
235 int globalsectorOUT = dBCALGeom->getglobalsector(moduleOUT,sectorOUT);
236 int globalsectormin, globalsectormax;
238 if (fADC_cellIdIN<=0 || fADC_cellIdOUT<=0) {
239 printf(
"BCCC >>Cells are not valid, event %i\n",eventnumber);
241 if (globalsectorIN == globalsectorOUT) {
246 printf(
"BCCC >> single sector layer: point (%6.3f,%6.3f) point (%6.3f,%6.3f)\n",
248 total_distance+=dist;
250 printf(
"BCCC >> (mod,lay,sec,glosec) = (%2i,%2i,%2i,%3i) fADC_cellId 0x%4x philess %6.3f, phimore %6.3f dist = %6.2f\n",
251 moduleIN,layer+1,sectorIN,globalsectorIN,fADC_cellIdIN,0.0,0.0,dist);
252 CellId_vec.push_back(fADC_cellIdIN);
253 distance_vec.push_back(dist);
257 if (globalsectorIN > globalsectorOUT) {
258 globalsectormin = globalsectorOUT;
259 globalsectormax = globalsectorIN;
261 globalsectormax = globalsectorOUT;
262 globalsectormin = globalsectorIN;
265 printf(
"BCCC >> layer=%i phi=%5.2f fADC_cellId 0x%4x (mod,sec) = (%2i,%2i) %3i\n",
266 layer, phi[
track][layer], fADC_cellIdIN, moduleIN, sectorIN, globalsectorIN);
267 printf(
"BCCC >> layer=%i phi=%5.2f fADC_cellId 0x%4x (mod,sec) = (%2i,%2i) %3i\n",
268 layer, phi[
track][layer+1], fADC_cellIdOUT, moduleOUT, sectorOUT, globalsectorOUT);
271 for (
int glosect=globalsectormin; glosect<=globalsectormax; glosect++) {
273 int sector = dBCALGeom->getsector(glosect);
274 int module = dBCALGeom->getmodule(glosect);
275 int fADCId = dBCALGeom->cellId(module,layer+1,sector);
276 float phi = dBCALGeom->phi(fADCId);
277 float phihalfSize = dBCALGeom->phiSize(fADCId)/2.;
278 float philess=phi-phihalfSize, phimore=phi+phihalfSize;
279 float mless, xless, yless, mmore, xmore, ymore;
282 mless = tan(philess);
283 mmore = tan(phimore);
284 xless = track_c/(mless-track_m);
285 yless = (mless*track_c)/(mless-track_m);
286 xmore = track_c/(mmore-track_m);
287 ymore = (mmore*track_c)/(mmore-track_m);
291 if (glosect==globalsectorIN) {
292 if (glosect==globalsectormin) {
298 if (glosect==globalsectorOUT) {
299 if (glosect==globalsectormin) {
312 CellId_vec.push_back(fADCId);
313 distance_vec.push_back(dist);
314 total_distance+=dist;
316 printf(
"BCCC >> (mod,lay,sec,glosec) = (%2i,%2i,%2i,%3i) fADC_cellId 0x%4x philess %6.3f, phimore %6.3f dist = %6.2f\n",
317 module,layer+1,sector,glosect,fADCId,philess,phimore,dist);
324 printf(
"BCCC >> total distance in BCAL: %f cm, expected %f\n",total_distance,dist);
332 vector<const DBCALHit*> BCALHit_vec;
333 loop->Get(BCALHit_vec);
334 unsigned int num_BCALHit = BCALHit_vec.size();
337 map<int, const DBCALHit*>::iterator myiter;
338 map<int, const DBCALHit*> upstream;
339 map<int, const DBCALHit*> downstream;
341 for(
unsigned int c_chan=0; c_chan<num_BCALHit; c_chan++){
342 const DBCALHit *BCALHit = BCALHit_vec[c_chan];
344 int fADCId = dBCALGeom->cellId( BCALHit->
module, BCALHit->
layer, BCALHit->
sector );
346 printf(
"BCCC >> Hit: (module, layer, sector) = (%2i,%2i,%2i) fADCId 0x%x\n",\
350 upstream[fADCId] = BCALHit;
353 downstream[fADCId] = BCALHit;
355 printf(
"BCCC >>Bad BCAL enum\n");
360 printf(
"BCCC >> found %ld upstream and %ld downstream hits for map.\n",upstream.size(),downstream.size());
364 japp->RootWriteLock();
366 eventnum = eventnumber;
368 unsigned int num_CellId = CellId_vec.size();
369 for (
unsigned int cellnum=0; cellnum<num_CellId; cellnum++) {
370 cell = CellId_vec[cellnum];
371 tdist = distance_vec[cellnum];
372 tmodule = dBCALGeom->module( cell );
373 tlayer = dBCALGeom->layer( cell );
374 tsector = dBCALGeom->sector( cell );
375 tglobalsect = dBCALGeom->getglobalsector(tmodule,tsector);
376 numcells = num_CellId;
379 myiter = upstream.find(cell);
380 if (myiter!=upstream.end()) {
381 const DBCALHit* US = myiter->second;
384 myiter = downstream.find(cell);
385 if (myiter!=downstream.end()) {
386 const DBCALHit* DS = myiter->second;
390 printf(
"BCCC >> eventnum %4i cellnum %2i 0x%4x (mod,lay,sec) = (%2i,%2i,%2i) %3i %6.2f %6.2f %6.2f \n",
391 eventnum, cellnum, cell, tmodule, tlayer, tsector, tglobalsect, tdist, use, dse);
393 bcal_calib_cosmic_cdc_tree->Fill();
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
float getposphi(float x, float y)
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
~JEventProcessor_bcal_calib_cosmic_cdc()
const DVector3 & position(void) const
float getdistance(float x1, float y1, float x2, float y2)
JEventProcessor_bcal_calib_cosmic_cdc()
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t init(void)
Called once at program start.
float gety(float r, float phi)
float getr(float x, float y)
<A href="index.html#legend"> <IMG src="CORE.png" width="100"> </A>
float chisq
Chi-squared for the track (not chisq/dof!)
const DVector3 & momentum(void) const
float getx(float r, float phi)
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
int Ndof
Number of degrees of freedom in the fit.
printf("string=%s", string)