8 #ifdef IS_REAL_L2 //in l2-ana environment
9 #include "../L2algoUtil/L2EmcDb.h"
10 #include "../L2algoUtil/L2Histo.h"
11 #else //full path needed for cvs'd code
12 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcDb.h"
13 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
14 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcGeom.h"
17 #include "L2Upsilon2009.h"
18 #include "read_in_geog.h"
24 L2Upsilon2009::L2Upsilon2009(
const char* name,
L2EmcDb* db,
L2EmcGeom *geoX,
char* outDir,
int resOff) :
L2VirtualAlgo2009( name, db, outDir, true, false, resOff) {
31 criticalError(
"L2Upsilon2009 is broken -- can't find geom.");
39 criticalError(
"L2Upsilon2009 has failed consistency check 'sizeof(L2UpsilonResult2009)== L2UpsilonResult2009::mySizeChar'");
48 L2Upsilon2009::initRunUser(
int runNo,
int *rc_ints,
float *rc_floats) {
52 par_prescale = rc_ints[0];
53 fMaxDynamicMaskTowers =rc_ints[1];
54 fHowManyEventPerUpdateDynamicMask=rc_ints[2];
55 par_RndAcceptPrescale=rc_ints[3];
57 fL0SeedThreshold = rc_floats[0];
58 fL2SeedThreshold = rc_floats[1];
59 fMinL0ClusterEnergy = rc_floats[2];
60 fMinL2ClusterEnergy = rc_floats[3];
61 fMinInvMass = rc_floats[4];
62 fMaxInvMass = rc_floats[5];
63 fMaxCosTheta = rc_floats[6];
64 fHotTowerThreshold=rc_floats[7];
65 fThresholdRatioOfHotTower=rc_floats[8];
67 fHotTowerSeenTimesThreshold=int(fHowManyEventPerUpdateDynamicMask*fThresholdRatioOfHotTower);
102 memset(wrkDynamicMask_tower_stat,0,
sizeof(wrkDynamicMask_tower_stat));
107 kBad+=0x00001 * (fMaxCosTheta>1.0||fMaxCosTheta<-1.0);
108 kBad+=0x00002 * (fL0SeedThreshold<fL2SeedThreshold);
109 kBad+=0x00004 * (fMinL0ClusterEnergy<fMinL2ClusterEnergy);
110 kBad+=0x00008 * (fMinInvMass>fMaxInvMass);
111 kBad+=0x00010 * (fHowManyEventPerUpdateDynamicMask<fHotTowerSeenTimesThreshold);
112 kBad+=0x00020 * (fMaxDynamicMaskTowers>100);
113 kBad+=0x00040 * (fThresholdRatioOfHotTower>1);
116 fprintf(mLogFile,
" L2%s upsilon algorithm initRun(R=%d), compiled: %s , %s\n params:\n",getName(),mRunNumber,__DATE__,__TIME__);
117 fprintf(mLogFile,
" initRun() params checked for consistency, Error flag=%d\n",kBad);
118 fprintf(mLogFile,
" prescale=%d \n", par_prescale);
119 fprintf(mLogFile,
" rndAccept prescale=%d \n", par_RndAcceptPrescale);
120 fprintf(mLogFile,
" L0SeedThreshold= %.2f (GeV)\n",fL0SeedThreshold);
121 fprintf(mLogFile,
" L2SeedThreshold= %.2f (GeV)\n",fL2SeedThreshold);
122 fprintf(mLogFile,
" MinL0ClusterEnergy= %.2f (GeV)\n",fMinL0ClusterEnergy);
123 fprintf(mLogFile,
" MinL2ClusterEnergy= %.2f (GeV)\n",fMinL2ClusterEnergy);
124 fprintf(mLogFile,
" MinInvMass= %.2f (GeV)\n",fMinInvMass);
125 fprintf(mLogFile,
" MaxInvMass= %.2f (GeV)\n",fMaxInvMass);
126 fprintf(mLogFile,
" MaxCosTheta= %.2f \n",fMaxCosTheta);
127 fprintf(mLogFile,
" MaxDynamicMaskedTowers= %d (should not greater than 100) \n",fMaxDynamicMaskTowers);
128 fprintf(mLogFile,
" HotTowerThreshold= %f (GeV) \n",fHotTowerThreshold);
129 fprintf(mLogFile,
" HowManyEventsPerUpdateDynamicMask= %d \n",fHowManyEventPerUpdateDynamicMask);
130 fprintf(mLogFile,
" fHotTowerSeenTimesThreshold= %d \n",fHotTowerSeenTimesThreshold);
131 fprintf(mLogFile,
" fThresholdRatioOfHotTower= %f (count_hot / count_check) \n",fThresholdRatioOfHotTower);
137 for (i=0; i<mxHA;i++)
if(hA[i])hA[i]->reset();
138 memset(mBtow,0,
sizeof(mBtow));
140 if(kBad>0)
return -1*kBad;
141 else if(kBad<0)
return kBad;
143 for (
int index=0; index<EmcDbIndexMax; index++ )
146 if ( x==0 )
continue;
147 if ( !mDb->isBTOW(x) )
continue;
148 int sec = x->sec - 1;
151 int eta = x->eta - 1;
152 int phi = BtowGeom::mxSubs *sec + sub;
153 int tow = BtowGeom::mxEtaBin *phi + eta;
155 if (tow<0 || tow>mxBtow || rdo<0 || rdo>mxBtow)
return -101;
157 mTower2rdo[ tow ] = rdo;
158 mRdo2tower[ rdo ] = tow;
161 sscanf(x->tube,
"id%d-%d-%d-%d",&a,&b,&c,&d);
162 rdo2softID[x->rdo]=a;
173 L2Upsilon2009::computeUser(
int token){
177 if(EventSeen%fHowManyEventPerUpdateDynamicMask==0) update_DynamicMask();
181 const int hitSize=mEveStream_btow[token].get_hitSize();
183 for(
int i=0;i< hitSize;i++,hit++) {
185 int tower=rdo2softID[hit->rdo];
186 wrkBtow_tower[i]=tower;
187 wrkBtow_ene[tower]=hit->ene;
188 if(wrkBtow_ene[tower] > fHotTowerThreshold) wrkDynamicMask_tower_stat[tower]++;
189 hA[2]->fill(
int(wrkBtow_ene[tower]));
191 hA[1]->fill(hitSize);
194 for(
int j=0;j<wrkNumberOfMasked;j++)
195 wrkBtow_ene[wrkDynamicMasked_tower[j]]=0;
200 for(
int i=0;i< hitSize;i++) {
201 int tower=wrkBtow_tower[i];
202 if(wrkBtow_ene[tower] > fL2SeedThreshold){
203 float clusterE=wrkBtow_ene[tower];
204 for(
int k=0;k<geog_Nneighbors[tower];k++){
205 float Ek=wrkBtow_ene[geog_neighbor[tower][k]];
207 for(
int m=0;m<geog_Nneighbors[tower];m++){
209 if(Ek<wrkBtow_ene[geog_neighbor[tower][m]])Ecount++;
211 if(Ecount<2)clusterE+=Ek;
214 if(clusterE>fMinL2ClusterEnergy) {
215 wrkL2_seed_tower[wrkNumberOfL2]=tower;
216 wrkL2_seed_ClusterE[wrkNumberOfL2]=clusterE;
217 hA[6]->fill(
int(wrkBtow_ene[tower]));
218 hA[8]->fill(
int(clusterE));
220 if(wrkBtow_ene[tower] > fL0SeedThreshold&&clusterE>fMinL0ClusterEnergy) {
221 wrkL0_seed_tower[wrkNumberOfL0]=tower;
222 wrkL0_seed_ClusterE[wrkNumberOfL0]=clusterE;
223 hA[5]->fill(
int(wrkBtow_ene[tower]));
224 hA[7]->fill(
int(clusterE));
230 hA[3]->fill(wrkNumberOfL2,wrkNumberOfL0);
233 for(
int i=0;i<wrkNumberOfL0;i++){
235 float cosTheta,invMass;
236 idL0= wrkL0_seed_tower[i];
237 for(
int j=0;j<wrkNumberOfL2;j++){
238 idL2= wrkL2_seed_tower[j];
239 if(idL0==idL2)
continue;
240 cosTheta=geog_x[idL0]*geog_x[idL2]+geog_y[idL0]*geog_y[idL2]+geog_z[idL0]*geog_z[idL2];
241 if(cosTheta>fMaxCosTheta)
continue;
242 invMass = sqrt(2 *wrkL0_seed_ClusterE[i] * wrkL2_seed_ClusterE[j] * (1 - cosTheta));
243 if(fMinInvMass>invMass || invMass>fMaxInvMass)
continue;
244 hA[10]->fill(
int(invMass));
246 btowEve->resultBlob.L0SeedTowerID=idL0;
247 btowEve->resultBlob.L2SeedTowerID=idL2;
248 if(wrkL0_seed_ClusterE[i]>25.5)wrkL0_seed_ClusterE[i]=25.5;
249 if(wrkL0_seed_ClusterE[j]>25.5)wrkL0_seed_ClusterE[j]=25.5;
250 if(invMass>25.5)invMass=25.5;
251 btowEve->resultBlob.energyOfL0Cluster=(
unsigned char)(wrkL0_seed_ClusterE[i]*10);
252 btowEve->resultBlob.energyOfL2Cluster=(
unsigned char)(wrkL2_seed_ClusterE[j]*10);
253 btowEve->resultBlob.invMass=(
unsigned char)(invMass*10);
254 btowEve->resultBlob.trigger=
true;
261 btowEve->resultBlob.L0SeedTowerID=5555;
262 btowEve->resultBlob.L2SeedTowerID=5555;
263 btowEve->resultBlob.energyOfL0Cluster=0;
264 btowEve->resultBlob.energyOfL2Cluster=0;
265 btowEve->resultBlob.invMass=0;
266 btowEve->resultBlob.trigger=
false;
276 L2Upsilon2009::decisionUser(
int token,
int *myL2Result){
284 if (par_prescale > 1) {
286 prescale%=par_prescale;
287 if(prescale!=0) btowEve->resultBlob.trigger=
false;
292 if(btowEve->resultBlob.trigger){
295 hA[14]->fill(btowEve->resultBlob.L0SeedTowerID);
296 hA[15]->fill(btowEve->resultBlob.L2SeedTowerID);
297 hA[16]->fill(
int((btowEve->resultBlob.energyOfL0Cluster)*0.1));
298 hA[17]->fill(
int((btowEve->resultBlob.energyOfL2Cluster)*0.1));
299 hA[18]->fill(
int((btowEve->resultBlob.invMass)*0.1));
301 else hA[13]->fill(3);
303 return btowEve->resultBlob.trigger;
310 L2Upsilon2009::finishRunUser() {
314 fprintf(mLogFile,
"finishRunUser - %s \n",getName());
315 fprintf(mLogFile,
"EventSeen = %d \n",EventSeen);
316 fprintf(mLogFile,
"event accept = %d \n",event_accept);
325 L2Upsilon2009::createHisto() {
329 hA[1]=
new L2Histo(1,
"Upsilon:# of hits (no L0 required)", 200);
330 hA[2]=
new L2Histo(2,
"Upsilon:energy for all hits (GeV) (no L0 required)", 20);
331 hA[3]=
new L2Histo(3,
"Upsilon: # of L0 candidates vs. # of L2 candidates (no L0 required)", 50,50);
333 hA[5]=
new L2Histo(5,
"Upsilon: L0 seeds Energy (GeV) (no L0 required)", 20);
334 hA[6]=
new L2Histo(6,
"Upsilon: L2 seeds Energy (GeV) (no L0 required)", 20);
336 hA[7]=
new L2Histo(7,
"Upsilon: L0 cluster Energy (GeV) (no L0 required)", 25);
337 hA[8]=
new L2Histo(8,
"Upsilon: L2 cluster Energy (GeV) (no L0 required)", 25);
339 hA[10]=
new L2Histo(10,
"Upsilon: InvMass of accepted pair (GeV) (no L0 required)", 25);
340 hA[11]=
new L2Histo(11,
"Upsilon: # of masked towers (no L0 required)", 100);
341 hA[12]=
new L2Histo(12,
"Upsilon: masked tower softid (no L0 required) ", 4801);
343 hA[13] =
new L2Histo(13,
"Upsilon: L0 counter (1=L0 fired, 2=L0 fired+L2 accepted, 3=L0 fired+L2 NOT accepted)",5);
344 hA[14] =
new L2Histo(14,
"Upsilon: L0 seed tower id (L0 fired+L2 accepted)",4801);
345 hA[15] =
new L2Histo(15,
"Upsilon: L2 seed tower id (L0 fired+L2 accepted)",4801);
346 hA[16]=
new L2Histo(16,
"Upsilon: L0 cluster Energy (GeV) (L0 fired+L2 accepted)", 25);
347 hA[17]=
new L2Histo(17,
"Upsilon: L2 cluster Energy (GeV) (L0 fired+L2 accepted)", 25);
348 hA[18]=
new L2Histo(18,
"Upsilon: InvMass of accepted pair (GeV) (L0 fired+L2 accepted)", 25);
357 L2Upsilon2009::clearEvent(
int token){
358 memset(wrkBtow_ene,0,
sizeof(wrkBtow_ene));
359 memset(wrkBtow_tower,0,
sizeof(wrkBtow_tower));
360 memset(wrkL2_seed_tower,0,
sizeof(wrkL2_seed_tower));
361 memset(wrkL2_seed_ClusterE,0,
sizeof(wrkL2_seed_ClusterE));
362 memset(wrkL0_seed_tower,0,
sizeof(wrkL0_seed_tower));
363 memset(wrkL0_seed_ClusterE,0,
sizeof(wrkL0_seed_ClusterE));
365 wrkNumberOfL2=wrkNumberOfL0=0;
369 L2Upsilon2009::update_DynamicMask(){
371 for(
int i=0;i<mxBtow;i++){
372 if(wrkDynamicMask_tower_stat[i]>fHotTowerSeenTimesThreshold && count<fMaxDynamicMaskTowers){
373 wrkDynamicMasked_tower[count]=i;
378 memset(wrkDynamicMask_tower_stat,0,
sizeof(wrkDynamicMask_tower_stat));
379 wrkNumberOfMasked=count;