| 1 | #include <CaloProfile.h> | 
| 2 | // | 
| 3 | ClassImp(CaloLat); | 
| 4 | ClassImp(CaloLong); | 
| 5 | ClassImp(Calo2D); | 
| 6 |  | 
| 7 | //////////////////////////////////////////////////////////////////////// | 
| 8 | /** | 
| 9 | * 1-dimension function describing lateral distribution of the | 
| 10 | * shower as viewed by calorimeter | 
| 11 | * (projection of 3d function in one direction) | 
| 12 | * | 
| 13 | *  xi[0] = x or y coordinate relative to shower axis | 
| 14 | *  parmin[0] = rt | 
| 15 | *  parmin[1] = p | 
| 16 | *  parmin[2] = rc | 
| 17 | * | 
| 18 | */ | 
| 19 | //////////////////////////////////////////////////////////////////////// | 
| 20 | Double_t cfradx(Double_t *xi, Double_t *parmin) { | 
| 21 |  | 
| 22 | double fradxmin2,p,rt,rc,es,x,pig,norm,c; | 
| 23 | x=*xi; | 
| 24 | pig = acos(-1.); | 
| 25 | rt=parmin[0]; | 
| 26 | p=parmin[1]; | 
| 27 | rc=parmin[2]; | 
| 28 | norm=parmin[3]; | 
| 29 | c=parmin[4]; | 
| 30 | x=x-c; | 
| 31 | es=1.5; | 
| 32 | fradxmin2=p*pig*pow(rc,2)/pow((pow(x,2)+pow(rc,2)),es); | 
| 33 | fradxmin2=fradxmin2+(1-p)*pig*pow(rt,2)/pow((pow(x,2)+pow(rt,2)),es); | 
| 34 | fradxmin2=norm*fradxmin2/(2*pig); | 
| 35 | //cout<<"x,fradxmin2 "<< x<<" "<<fradxmin2  <<endl; | 
| 36 | return fradxmin2; | 
| 37 | } | 
| 38 |  | 
| 39 |  | 
| 40 | Double_t cfunc(Double_t *tin,Double_t *par) | 
| 41 | { | 
| 42 |  | 
| 43 | Double_t gaa,a,tm,et,value,t,t0; | 
| 44 | t=*tin; | 
| 45 | et=par[0]; | 
| 46 | a=par[1]; | 
| 47 | tm=par[2]; | 
| 48 | t0=par[3]; | 
| 49 | gaa=TMath::Gamma(a); | 
| 50 |  | 
| 51 | value=et*((a-1)/(tm*gaa))*pow(((a-1)*(t-t0)/tm),(a-1))*exp(-(a-1)*(t-t0)/tm); | 
| 52 | return value; | 
| 53 | } | 
| 54 |  | 
| 55 |  | 
| 56 | //-------------------------------------- | 
| 57 | /** | 
| 58 | * Default constructor | 
| 59 | */ | 
| 60 | CaloLat::CaloLat(){ | 
| 61 | Clear(); | 
| 62 | }; | 
| 63 |  | 
| 64 | /** | 
| 65 | * Default constructor | 
| 66 | */ | 
| 67 | Calo2D::Calo2D(){ | 
| 68 | Clear(); | 
| 69 | }; | 
| 70 |  | 
| 71 | CaloLat::CaloLat(PamLevel2 *l2p){ | 
| 72 | // | 
| 73 | Clear(); | 
| 74 | // | 
| 75 | L2 = l2p; | 
| 76 | // | 
| 77 | if ( !L2->IsORB() ) printf(" WARNING: OrbitalInfo Tree is needed, the plugin could not work properly without it \n"); | 
| 78 | // | 
| 79 | OBT = 0; | 
| 80 | PKT = 0; | 
| 81 | atime = 0; | 
| 82 | // | 
| 83 | debug = false; | 
| 84 | // | 
| 85 | }; | 
| 86 |  | 
| 87 | Calo2D::Calo2D(PamLevel2 *l2p){ | 
| 88 | // | 
| 89 | Clear(); | 
| 90 | // | 
| 91 | L2 = l2p; | 
| 92 | // | 
| 93 | if ( !L2->IsORB() ) printf(" WARNING: OrbitalInfo Tree is needed, the plugin could not work properly without it \n"); | 
| 94 | // | 
| 95 | OBT = 0; | 
| 96 | PKT = 0; | 
| 97 | atime = 0; | 
| 98 | // | 
| 99 | debug = false; | 
| 100 | // | 
| 101 | }; | 
| 102 |  | 
| 103 | void CaloLat::Clear(){ | 
| 104 | // | 
| 105 | }; | 
| 106 |  | 
| 107 | void Calo2D::Clear(){ | 
| 108 | // | 
| 109 | }; | 
| 110 |  | 
| 111 | void CaloLat::Print(){ | 
| 112 | // | 
| 113 | Process(); | 
| 114 | // | 
| 115 | printf("==================== Calorimeter Lateral Profile =======================\n"); | 
| 116 | printf(" OBT: %u PKT: %u ATIME: %u \n",OBT,PKT,atime); | 
| 117 | //  printf(" nx [number of X combination]:.. %i\n",nx); | 
| 118 | //  printf(" ny [number of Y combination]:.. %i\n",ny); | 
| 119 | printf("========================================================================\n"); | 
| 120 | // | 
| 121 | }; | 
| 122 |  | 
| 123 | void Calo2D::Print(){ | 
| 124 | // | 
| 125 | Process(); | 
| 126 | // | 
| 127 | printf("==================== Calorimeter 2D Profile =======================\n"); | 
| 128 | printf(" OBT: %u PKT: %u ATIME: %u \n",OBT,PKT,atime); | 
| 129 | //  printf(" nx [number of X combination]:.. %i\n",nx); | 
| 130 | //  printf(" ny [number of Y combination]:.. %i\n",ny); | 
| 131 | printf("========================================================================\n"); | 
| 132 | // | 
| 133 | }; | 
| 134 |  | 
| 135 | void CaloLat::Draw(){ | 
| 136 | // | 
| 137 | Process(); | 
| 138 | Draw(-1,-1); | 
| 139 | }; | 
| 140 |  | 
| 141 | void Calo2D::Draw(){ | 
| 142 | // | 
| 143 | Process(); | 
| 144 | Draw(-1); | 
| 145 | }; | 
| 146 |  | 
| 147 | void CaloLat::Draw(Int_t view,Int_t plane){ | 
| 148 | // | 
| 149 | Int_t minv = 0; | 
| 150 | Int_t maxv = 0; | 
| 151 | Int_t minp = 0; | 
| 152 | Int_t maxp = 0; | 
| 153 | // | 
| 154 | if ( view == -1 ){ | 
| 155 | minv = 0; | 
| 156 | maxv = 2; | 
| 157 | } else { | 
| 158 | minv = view; | 
| 159 | maxv = view+1; | 
| 160 | }; | 
| 161 |  | 
| 162 | if ( plane == -1 ){ | 
| 163 | minp = 0; | 
| 164 | maxp = 22; | 
| 165 | } else { | 
| 166 | minp = plane; | 
| 167 | maxp = plane+1; | 
| 168 | }; | 
| 169 | // | 
| 170 | Process(); | 
| 171 | // | 
| 172 | gStyle->SetLabelSize(0.04); | 
| 173 | gStyle->SetNdivisions(510,"XY"); | 
| 174 | // | 
| 175 | for (Int_t v=minv; v<maxv;v++){ | 
| 176 | for (Int_t p=minp; p<maxp;p++){ | 
| 177 | TString hid = Form("clatv%ip%i",v,p); | 
| 178 | TCanvas *tc  = dynamic_cast<TCanvas*>(gDirectory->FindObject(hid)); | 
| 179 | if ( tc ){ | 
| 180 | //       tc->Clear(); | 
| 181 | } else { | 
| 182 | tc = new TCanvas(hid,hid); | 
| 183 | }; | 
| 184 | // | 
| 185 | TString thid = Form("hlatv%ip%i",v,p); | 
| 186 | TH1F *th  = dynamic_cast<TH1F*>(gDirectory->FindObject(thid)); | 
| 187 | if ( th ) th->Delete(); | 
| 188 | //       th->Clear(); | 
| 189 | //       th->Reset(); | 
| 190 | //      } else { | 
| 191 | th = new TH1F(thid,thid,96,-0.5,95.5); | 
| 192 | //      }; | 
| 193 | tc->cd(); | 
| 194 | // | 
| 195 | for (Int_t st=0;st<96;st++){ | 
| 196 | th->Fill(st,estrip[v][p][st]); | 
| 197 | }; | 
| 198 | th->Draw(); | 
| 199 | tc->Modified(); | 
| 200 | tc->Update(); | 
| 201 | }; | 
| 202 | }; | 
| 203 | // | 
| 204 | gStyle->SetLabelSize(0); | 
| 205 | gStyle->SetNdivisions(1,"XY"); | 
| 206 | // | 
| 207 | }; | 
| 208 |  | 
| 209 | void Calo2D::Draw(Int_t plane){ | 
| 210 | // | 
| 211 | Int_t minp = 0; | 
| 212 | Int_t maxp = 0; | 
| 213 | // | 
| 214 | if ( plane == -1 ){ | 
| 215 | minp = 0; | 
| 216 | maxp = 23; | 
| 217 | } else { | 
| 218 | minp = plane; | 
| 219 | maxp = plane+1; | 
| 220 | }; | 
| 221 | // | 
| 222 | Process(); | 
| 223 | // | 
| 224 | gStyle->SetLabelSize(0.04); | 
| 225 | gStyle->SetNdivisions(510,"XY"); | 
| 226 | // | 
| 227 | for (Int_t p=minp; p<maxp;p++){ | 
| 228 | TString hid = Form("c2dp%i",p); | 
| 229 | TCanvas *tc  = dynamic_cast<TCanvas*>(gDirectory->FindObject(hid)); | 
| 230 | if ( tc ){ | 
| 231 | //         tc->Clear(); | 
| 232 | } else { | 
| 233 | tc = new TCanvas(hid,hid); | 
| 234 | }; | 
| 235 | // | 
| 236 | TString thid = Form("h2dp%i",p); | 
| 237 | TH2F *th  = dynamic_cast<TH2F*>(gDirectory->FindObject(thid)); | 
| 238 | if ( th ) th->Delete(); | 
| 239 | //   th->Clear(); | 
| 240 | //   th->Reset(); | 
| 241 | //  } else { | 
| 242 | Int_t minx = smax[p] - 10; | 
| 243 | if ( minx < 0 ) minx = 0; | 
| 244 | Int_t maxx = minx + 20; | 
| 245 | if ( maxx > 95 ){ | 
| 246 | maxx = 95; | 
| 247 | minx = 75; | 
| 248 | }; | 
| 249 | Int_t miny = smay[p] - 10; | 
| 250 | if ( miny < 0 ) miny = 0; | 
| 251 | Int_t maxy = miny + 20; | 
| 252 | if ( maxy > 95 ){ | 
| 253 | maxy = 95; | 
| 254 | miny = 75; | 
| 255 | }; | 
| 256 | th = new TH2F(thid,thid,20,(Float_t)minx-0.5,(Float_t)maxx-0.5,20,(Float_t)miny-0.5,(Float_t)maxy-0.5); | 
| 257 | //    th = new TH2F(thid,thid,96,-0.5,95.5,96,-0.5,95.5); | 
| 258 | //  }; | 
| 259 | tc->cd(); | 
| 260 | // | 
| 261 | for (Int_t stx=minx;stx<maxx+1;stx++){ | 
| 262 | for (Int_t sty=miny;sty<maxy+1;sty++){ | 
| 263 | th->Fill(stx,sty,estrip[p][stx][sty]); | 
| 264 | }; | 
| 265 | }; | 
| 266 | gStyle->SetPalette(1); | 
| 267 | //    tc->SetLogz(); | 
| 268 | //    th->Draw("colbox"); | 
| 269 | th->Draw("cont4"); | 
| 270 | tc->Modified(); | 
| 271 | tc->Update(); | 
| 272 | }; | 
| 273 | // | 
| 274 | gStyle->SetLabelSize(0); | 
| 275 | gStyle->SetNdivisions(1,"XY"); | 
| 276 | // | 
| 277 | }; | 
| 278 |  | 
| 279 | void CaloLat::Delete(){ | 
| 280 | Clear(); | 
| 281 | //delete this; | 
| 282 | }; | 
| 283 |  | 
| 284 | void Calo2D::Delete(){ | 
| 285 | Clear(); | 
| 286 | //delete this; | 
| 287 | }; | 
| 288 |  | 
| 289 |  | 
| 290 | void CaloLat::Process(){ | 
| 291 | // | 
| 292 | if ( !L2 ){ | 
| 293 | printf(" ERROR: cannot find PamLevel2 object, use the correct constructor or check your program!\n"); | 
| 294 | printf(" ERROR: CaloHough variables not filled \n"); | 
| 295 | return; | 
| 296 | }; | 
| 297 | // | 
| 298 | Bool_t newentry = false; | 
| 299 | // | 
| 300 | if ( L2->IsORB() ){ | 
| 301 | if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime ){ | 
| 302 | newentry = true; | 
| 303 | OBT = L2->GetOrbitalInfo()->OBT; | 
| 304 | PKT = L2->GetOrbitalInfo()->pkt_num; | 
| 305 | atime = L2->GetOrbitalInfo()->absTime; | 
| 306 | }; | 
| 307 | } else { | 
| 308 | newentry = true; | 
| 309 | }; | 
| 310 | // | 
| 311 | if ( !newentry ) return; | 
| 312 | // | 
| 313 | if ( debug ) printf(" Start processing event at OBT %u PKT %u time %u \n",OBT,PKT,atime); | 
| 314 | // | 
| 315 | Clear(); | 
| 316 | // | 
| 317 | // let's start | 
| 318 | // | 
| 319 | memset(estrip,0, 4224*sizeof(Float_t)); | 
| 320 | Float_t mip1 = 0.; | 
| 321 | Int_t view1 = 0; | 
| 322 | Int_t plane1 = 0; | 
| 323 | Int_t strip1 = 0; | 
| 324 | // | 
| 325 | for (Int_t i=0; i<L2->GetCaloLevel1()->istrip ; i++){ | 
| 326 | mip1 = L2->GetCaloLevel1()->DecodeEstrip(i,view1,plane1,strip1); | 
| 327 | estrip[view1][plane1][strip1] = mip1; | 
| 328 | }; | 
| 329 | // | 
| 330 | if ( debug ) this->Print(); | 
| 331 | if ( debug ) printf(" exit \n"); | 
| 332 | // | 
| 333 | }; | 
| 334 |  | 
| 335 | void Calo2D::Process(){ | 
| 336 | // | 
| 337 | if ( !L2 ){ | 
| 338 | printf(" ERROR: cannot find PamLevel2 object, use the correct constructor or check your program!\n"); | 
| 339 | printf(" ERROR: CaloHough variables not filled \n"); | 
| 340 | return; | 
| 341 | }; | 
| 342 | // | 
| 343 | Bool_t newentry = false; | 
| 344 | // | 
| 345 | if ( L2->IsORB() ){ | 
| 346 | if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime ){ | 
| 347 | newentry = true; | 
| 348 | OBT = L2->GetOrbitalInfo()->OBT; | 
| 349 | PKT = L2->GetOrbitalInfo()->pkt_num; | 
| 350 | atime = L2->GetOrbitalInfo()->absTime; | 
| 351 | }; | 
| 352 | } else { | 
| 353 | newentry = true; | 
| 354 | }; | 
| 355 | // | 
| 356 | if ( !newentry ) return; | 
| 357 | // | 
| 358 | if ( debug ) printf(" Start processing event at OBT %u PKT %u time %u \n",OBT,PKT,atime); | 
| 359 | // | 
| 360 | Clear(); | 
| 361 | // | 
| 362 | // let's start | 
| 363 | // | 
| 364 | Float_t es[2][22][96]; | 
| 365 | memset(es,0, 4224*sizeof(Float_t)); | 
| 366 | memset(estrip,0, 4224*sizeof(Float_t)); | 
| 367 | Float_t mip1 = 0.; | 
| 368 | Int_t view1 = 0; | 
| 369 | Int_t plane1 = 0; | 
| 370 | Int_t strip1 = 0; | 
| 371 | // | 
| 372 | for (Int_t i=0; i<L2->GetCaloLevel1()->istrip ; i++){ | 
| 373 | mip1 = L2->GetCaloLevel1()->DecodeEstrip(i,view1,plane1,strip1); | 
| 374 | es[view1][plane1][strip1] = mip1; | 
| 375 | }; | 
| 376 | // | 
| 377 | Int_t plane2 = 0; | 
| 378 | Float_t emax[23]; | 
| 379 | memset(emax,0,sizeof(Float_t)*23); | 
| 380 | memset(smax,0,sizeof(Int_t)*23); | 
| 381 | memset(smay,0,sizeof(Int_t)*23); | 
| 382 | // | 
| 383 | // | 
| 384 | for (Int_t p=0; p < 23 ; p++){ | 
| 385 | // | 
| 386 | plane1 = p-1; | 
| 387 | plane2 = p; | 
| 388 | // | 
| 389 | if ( p == 0 ){ | 
| 390 | plane1 = -1; | 
| 391 | plane2 = 0; | 
| 392 | }; | 
| 393 | if ( p == 22 ){ | 
| 394 | plane1 = 21; | 
| 395 | plane2 = -1; | 
| 396 | }; | 
| 397 | // | 
| 398 | for (Int_t s=0; s < 96 ; s++){ // x | 
| 399 | for (Int_t ss=0; ss < 96 ; ss++){ // y | 
| 400 | if ( p == 0 ){ | 
| 401 | estrip[p][s][ss] += es[1][plane2][ss]; | 
| 402 | if ( (es[1][plane2][ss]) > emax[p] ){ | 
| 403 | smax[p] = 45; | 
| 404 | smay[p] = ss; | 
| 405 | emax[p] = es[1][plane2][ss] ; | 
| 406 | }; | 
| 407 | }; | 
| 408 | if ( p > 0 && p < 22 ){ | 
| 409 | estrip[p][s][ss] += es[0][plane1][s] + es[1][plane2][ss]; | 
| 410 | if ( (es[0][plane1][s] + es[1][plane2][ss]) > emax[p] ){ | 
| 411 | smax[p] = s; | 
| 412 | smay[p] = ss; | 
| 413 | emax[p] = es[0][plane1][s] + es[1][plane2][ss] ; | 
| 414 | }; | 
| 415 | }; | 
| 416 | if ( p == 22 ){ | 
| 417 | estrip[p][s][ss] += es[0][plane1][s]; | 
| 418 | if ( (es[1][plane2][s]) > emax[p] ){ | 
| 419 | smax[p] = s; | 
| 420 | smay[p] = 45; | 
| 421 | emax[p] = es[1][plane2][s] ; | 
| 422 | }; | 
| 423 | }; | 
| 424 | }; | 
| 425 | }; | 
| 426 | // | 
| 427 | }; | 
| 428 | // | 
| 429 | if ( debug ) this->Print(); | 
| 430 | if ( debug ) printf(" exit \n"); | 
| 431 | // | 
| 432 | }; | 
| 433 |  | 
| 434 |  | 
| 435 | /** | 
| 436 | * Default constructor | 
| 437 | */ | 
| 438 | CaloLong::CaloLong(){ | 
| 439 | Clear(); | 
| 440 | }; | 
| 441 |  | 
| 442 | CaloLong::CaloLong(PamLevel2 *l2p){ | 
| 443 | // | 
| 444 | Clear(); | 
| 445 | // | 
| 446 | L2 = l2p; | 
| 447 | // | 
| 448 | if ( !L2->IsORB() ) printf(" WARNING: OrbitalInfo Tree is needed, the plugin could not work properly without it \n"); | 
| 449 | // | 
| 450 | OBT = 0; | 
| 451 | PKT = 0; | 
| 452 | atime = 0; | 
| 453 | // | 
| 454 | sel = true; | 
| 455 | cont = false; | 
| 456 | N = 0; | 
| 457 | NC = 22; | 
| 458 | mask18b = -1; | 
| 459 | // | 
| 460 | no18x = true; | 
| 461 | debug = false; | 
| 462 | // | 
| 463 | }; | 
| 464 |  | 
| 465 | void CaloLong::Clear(){ | 
| 466 | // | 
| 467 | memset(eplane,0, 2*22*sizeof(Float_t)); | 
| 468 | // | 
| 469 | chi2 = 0.; | 
| 470 | ndf = 0.; | 
| 471 | E0 = 0.; | 
| 472 | a = 0.; | 
| 473 | b = 0.; | 
| 474 | errE0 = 0.; | 
| 475 | erra = 0.; | 
| 476 | errb = 0.; | 
| 477 | etmax = 0.; | 
| 478 | asymm = 0.; | 
| 479 | fitresult = 0; | 
| 480 | // | 
| 481 | X0pl = 0.76; | 
| 482 | // | 
| 483 | }; | 
| 484 |  | 
| 485 | void CaloLong::Print(){ | 
| 486 | // | 
| 487 | Process(); | 
| 488 | // | 
| 489 | printf("==================== Calorimeter Longitudinal Profile =======================\n"); | 
| 490 | printf(" OBT: %u PKT: %u ATIME: %u \n",OBT,PKT,atime); | 
| 491 | printf(" fitresult:.. %i\n",fitresult); | 
| 492 | printf(" chi2     :.. %f\n",chi2); | 
| 493 | printf(" ndf      :.. %f\n",ndf); | 
| 494 | printf(" nchi2    :.. %f\n",chi2/ndf); | 
| 495 | printf(" E0       :.. %f\n",E0); | 
| 496 | printf(" E0/260.  :.. %f\n",E0/260.); | 
| 497 | printf(" a        :.. %f\n",a); | 
| 498 | printf(" b        :.. %f\n",b); | 
| 499 | printf(" errE0    :.. %f\n",errE0); | 
| 500 | printf(" erra     :.. %f\n",erra); | 
| 501 | printf(" errb     :.. %f\n",errb); | 
| 502 | printf(" asymm    :.. %f\n",asymm); | 
| 503 | printf(" tmax     :.. %f\n",((a-1.)/b)); | 
| 504 | printf(" etmax    :.. %f\n",etmax); | 
| 505 | printf(" X0pl     :.. %f\n",X0pl); | 
| 506 | printf("========================================================================\n"); | 
| 507 | // | 
| 508 | }; | 
| 509 |  | 
| 510 | void CaloLong::SetNoWpreSampler(Int_t n){ | 
| 511 | // | 
| 512 | if ( NC+n <= 22 && NC+n >= 0 ){ | 
| 513 | N = n; | 
| 514 | } else { | 
| 515 | printf(" ERROR! Calorimeter is made of 22 W planes\n"); | 
| 516 | printf(" you are giving N presampler = %i and N calo = %i \n",n,NC); | 
| 517 | printf(" WARNING: using default values NWpre = 0, NWcalo = 22\n"); | 
| 518 | NC = 22; | 
| 519 | N = 0; | 
| 520 | }; | 
| 521 | } | 
| 522 |  | 
| 523 | void CaloLong::SetNoWcalo(Int_t n){ | 
| 524 | if ( N+n <= 22 && N+n >= 0 ){ | 
| 525 | NC = n; | 
| 526 | } else { | 
| 527 | printf(" ERROR! Calorimeter is made of 22 W planes\n"); | 
| 528 | printf(" you are giving N W presampler = %i and N W calo = %i \n",N,n); | 
| 529 | printf(" WARNING: using default values NWpre = 0, NWcalo = 22\n"); | 
| 530 | NC = 22; | 
| 531 | N = 0; | 
| 532 | }; | 
| 533 | } | 
| 534 |  | 
| 535 | void CaloLong::SplitInto(Int_t NoWpreSampler, Int_t NoWcalo){ | 
| 536 | this->SetNoWpreSampler(0); | 
| 537 | this->SetNoWcalo(0); | 
| 538 | if ( NoWpreSampler < NoWcalo ){ | 
| 539 | this->SetNoWpreSampler(NoWpreSampler); | 
| 540 | this->SetNoWcalo(NoWcalo); | 
| 541 | } else { | 
| 542 | this->SetNoWcalo(NoWcalo); | 
| 543 | this->SetNoWpreSampler(NoWpreSampler); | 
| 544 | }; | 
| 545 | } | 
| 546 |  | 
| 547 | void CaloLong::Process(){ | 
| 548 | // | 
| 549 | if ( !L2 ){ | 
| 550 | printf(" ERROR: cannot find PamLevel2 object, use the correct constructor or check your program!\n"); | 
| 551 | printf(" ERROR: CaloHough variables not filled \n"); | 
| 552 | return; | 
| 553 | }; | 
| 554 | // | 
| 555 | Bool_t newentry = false; | 
| 556 | // | 
| 557 | if ( L2->IsORB() ){ | 
| 558 | if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime ){ | 
| 559 | newentry = true; | 
| 560 | OBT = L2->GetOrbitalInfo()->OBT; | 
| 561 | PKT = L2->GetOrbitalInfo()->pkt_num; | 
| 562 | atime = L2->GetOrbitalInfo()->absTime; | 
| 563 | }; | 
| 564 | } else { | 
| 565 | newentry = true; | 
| 566 | }; | 
| 567 | // | 
| 568 | if ( !newentry ) return; | 
| 569 | // | 
| 570 | if ( debug ) printf(" Start processing event at OBT %u PKT %u time %u \n",OBT,PKT,atime); | 
| 571 | // | 
| 572 | Clear(); | 
| 573 | // | 
| 574 | // let's start | 
| 575 | // | 
| 576 | if ( cont ){ | 
| 577 | for (Int_t i=0; i<22; i++){ | 
| 578 | if ( i == (18+N) ){ | 
| 579 | mask18b =  18 + N; | 
| 580 | break; | 
| 581 | }; | 
| 582 | }; | 
| 583 | }; | 
| 584 | // | 
| 585 | if ( sel ){ | 
| 586 | for (Int_t i=0; i<22; i++){ | 
| 587 | if ( i == (18-N) ){ | 
| 588 | mask18b =  18 - N; | 
| 589 | break; | 
| 590 | }; | 
| 591 | }; | 
| 592 | }; | 
| 593 | // | 
| 594 | //  if ( mask18b == 18 ) mask18b = -1; | 
| 595 | // | 
| 596 | Int_t view = 0; | 
| 597 | Int_t plane = 0; | 
| 598 | Int_t strip = 0; | 
| 599 | Float_t mip = 0.; | 
| 600 | for (Int_t i=0; i < L2->GetCaloLevel1()->istrip; i++){ | 
| 601 | mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip); | 
| 602 | eplane[view][plane] += mip; | 
| 603 | }; | 
| 604 | // | 
| 605 | // inclination factor (steal from Daniele's code) | 
| 606 | // | 
| 607 | Float_t ytgx = 0; | 
| 608 | Float_t ytgy = 0; | 
| 609 | ytgx = 0.76 * L2->GetCaloLevel2()->tanx[0]; | 
| 610 | ytgy = 0.76 * L2->GetCaloLevel2()->tany[0]; | 
| 611 | X0pl = sqrt( pow(0.76,2.) + pow(ytgx,2.) + pow(ytgy,2.) ); | 
| 612 | // | 
| 613 | // Find experimental plane of maximum | 
| 614 | // | 
| 615 | Int_t pmax = 0; | 
| 616 | Int_t vmax = 0; | 
| 617 | Float_t emax = 0.; | 
| 618 | for (Int_t v=0; v<2; v++){ | 
| 619 | for (Int_t i=0; i<22; i++){ | 
| 620 | if ( eplane[v][i] > emax ){ | 
| 621 | emax = eplane[v][i]; | 
| 622 | vmax = v; | 
| 623 | pmax = i; | 
| 624 | }; | 
| 625 | }; | 
| 626 | }; | 
| 627 | // | 
| 628 | // | 
| 629 | // | 
| 630 | if ( vmax == 0 ) pmax++; | 
| 631 | etmax = pmax * X0pl; | 
| 632 | // | 
| 633 | if ( debug ) this->Print(); | 
| 634 | if ( debug ) printf(" exit \n"); | 
| 635 | // | 
| 636 | }; | 
| 637 |  | 
| 638 |  | 
| 639 | Double_t ccurve(Double_t *ti,Double_t *par){ | 
| 640 | // | 
| 641 | Double_t t = *ti; | 
| 642 | Double_t cE0 = par[0]; | 
| 643 | Double_t ca = par[1]; | 
| 644 | Double_t cb = par[2]; | 
| 645 | Double_t gammaa = TMath::Gamma(ca); | 
| 646 | // | 
| 647 | Double_t value = cE0 * cb * ( pow((cb * t),(ca - 1)) * exp( -cb * t ) ) / gammaa; | 
| 648 | // | 
| 649 | return value; | 
| 650 | // | 
| 651 | } | 
| 652 |  | 
| 653 | void CaloLong::Fit(){ | 
| 654 | this->Fit(false); | 
| 655 | }; | 
| 656 |  | 
| 657 | void CaloLong::Fit(Bool_t draw){ | 
| 658 | // | 
| 659 | Process(); | 
| 660 | // | 
| 661 | // | 
| 662 | if ( !L2 ){ | 
| 663 | printf(" ERROR: cannot find PamLevel2 object, use the correct constructor or check your program!\n"); | 
| 664 | printf(" ERROR: CaloHough variables not filled \n"); | 
| 665 | return; | 
| 666 | }; | 
| 667 | // | 
| 668 | Bool_t newentry = false; | 
| 669 | // | 
| 670 | if ( L2->IsORB() ){ | 
| 671 | if ( L2->GetOrbitalInfo()->pkt_num != fPKT || L2->GetOrbitalInfo()->OBT != fOBT || L2->GetOrbitalInfo()->absTime != fatime ){ | 
| 672 | newentry = true; | 
| 673 | fOBT = L2->GetOrbitalInfo()->OBT; | 
| 674 | fPKT = L2->GetOrbitalInfo()->pkt_num; | 
| 675 | fatime = L2->GetOrbitalInfo()->absTime; | 
| 676 | }; | 
| 677 | } else { | 
| 678 | newentry = true; | 
| 679 | }; | 
| 680 | // | 
| 681 | if ( !newentry ) return; | 
| 682 | // | 
| 683 | if ( debug ) printf(" Start fitting event at OBT %u PKT %u time %u \n",fOBT,fPKT,fatime); | 
| 684 | // | 
| 685 | if ( draw ){ | 
| 686 | gStyle->SetLabelSize(0.04); | 
| 687 | gStyle->SetNdivisions(510,"XY"); | 
| 688 | }; | 
| 689 | // | 
| 690 | TString hid = Form("clongfit"); | 
| 691 | TCanvas *tc  = dynamic_cast<TCanvas*>(gDirectory->FindObject(hid)); | 
| 692 | //  if ( tc ) tc->Delete(); | 
| 693 | //  if ( tc ) tc->Close(); | 
| 694 | if ( !tc && draw ){ | 
| 695 | tc = new TCanvas(hid,hid); | 
| 696 | } else { | 
| 697 | if ( tc ) tc->cd(); | 
| 698 | }; | 
| 699 | // | 
| 700 | TString thid = Form("hlongfit"); | 
| 701 | TH1F *th  = dynamic_cast<TH1F*>(gDirectory->FindObject(thid)); | 
| 702 | if ( th ) th->Delete(); | 
| 703 | Float_t xpos = 0.; | 
| 704 | Float_t enemip = 0.; | 
| 705 | Float_t xmax = NC * X0pl + 0.2; | 
| 706 | //  th = new TH1F(thid,thid,int(NC*1.5),-0.2,xmax); | 
| 707 | th = new TH1F(thid,thid,100,-0.2,xmax); | 
| 708 | // | 
| 709 | for (Int_t st=N;st<(N+NC);st++){ | 
| 710 | enemip = 0.; | 
| 711 | xpos = (st - N) * X0pl; | 
| 712 | if ( st > N && st < (N+NC-1) ){ | 
| 713 | if ( no18x && ( st == 18+1 || st == mask18b+1 )){ | 
| 714 | enemip = 2. * eplane[1][st]; | 
| 715 | } else { | 
| 716 | enemip = eplane[0][st-1] + eplane[1][st]; | 
| 717 | }; | 
| 718 | } else { | 
| 719 | if ( st == N ) enemip = 2. * eplane[1][st]; | 
| 720 | if ( st == (N+NC-1) ) enemip = 2. * eplane[0][st]; | 
| 721 | }; | 
| 722 | // | 
| 723 | if ( enemip > 0. ){ | 
| 724 | th->Fill(xpos,enemip); | 
| 725 | if ( debug ) printf(" Filling: st %i xpos %f energy %f \n",st,xpos,enemip); | 
| 726 | }; | 
| 727 | // | 
| 728 | //    for (Int_t v=1; v>=0;v--)// { | 
| 729 | //       // | 
| 730 | //       if ( v == 1 ){ | 
| 731 | //      xpos = (st - N) * X0pl; | 
| 732 | //       } else { | 
| 733 | //      xpos = (st + 1 - N) * X0pl; | 
| 734 | //       }; | 
| 735 | //       // | 
| 736 | //       if ( no18x && st == 18 && v == 0 ){ | 
| 737 | //      // skip plane 18x | 
| 738 | //       } else { | 
| 739 | //      if ( v == 1 && st == mask18b ){ | 
| 740 | //        // emulate plane 18x | 
| 741 | //      } else { | 
| 742 | //        if ( eplane[v][st] > 0. ){ | 
| 743 | //          th->Fill(xpos,eplane[v][st]); | 
| 744 | //          if ( debug ) printf(" Filling: st %i v %i xpos %f energy %f \n",st,v,xpos,eplane[v][st]); | 
| 745 | //        }; | 
| 746 | //      }; | 
| 747 | //       }; | 
| 748 | //       // | 
| 749 | //     }; | 
| 750 | }; | 
| 751 | // | 
| 752 | TF1 *lfit = new TF1("lfit",ccurve,0.,xmax,3); | 
| 753 | E0 = L2->GetCaloLevel2()->qtot; | 
| 754 | a = 5.; | 
| 755 | b = 0.5; | 
| 756 | if ( debug ) printf(" STARTING PARAMETERS: E0 %f a %f b %f \n",E0,a,b); | 
| 757 | lfit->SetParameters(E0,a,b); | 
| 758 | //  lfit->SetParLimits(0,0.,1000.); | 
| 759 | //  lfit->SetParLimits(1,-1.,80.); | 
| 760 | //  lfit->SetParLimits(2,-1.,10.); | 
| 761 | TString optio; | 
| 762 | if ( debug ){ | 
| 763 | //    optio = "MERBOV"; | 
| 764 | //    optio = "MEROV"; | 
| 765 | //    optio = "EROV"; | 
| 766 | optio = "RNOV"; | 
| 767 | if ( draw ) optio = "ROV"; | 
| 768 | } else { | 
| 769 | //    optio = "MERNOQ"; | 
| 770 | //    optio = "ERNOQ"; | 
| 771 | optio = "RNOQ"; | 
| 772 | if ( draw ) optio = "ROQ"; | 
| 773 | }; | 
| 774 | // | 
| 775 | if ( debug ) printf(" OK, start the fitting procedure...\n"); | 
| 776 | // | 
| 777 | fitresult = th->Fit("lfit",optio); | 
| 778 | // | 
| 779 | if ( debug ) printf(" the fit is done! result: %i \n",fitresult); | 
| 780 | // | 
| 781 | E0 = lfit->GetParameter(0); | 
| 782 | a = lfit->GetParameter(1); | 
| 783 | b = lfit->GetParameter(2); | 
| 784 | errE0 = lfit->GetParError(0); | 
| 785 | erra = lfit->GetParError(1); | 
| 786 | errb = lfit->GetParError(2); | 
| 787 | chi2 = lfit->GetChisquare(); | 
| 788 | ndf = lfit->GetNDF(); | 
| 789 | Float_t tmax = 0.; | 
| 790 | if ( debug ) printf(" Parameters are retrieved \n"); | 
| 791 | if ( b != 0 ) tmax = (a - 1.)/b; | 
| 792 | // | 
| 793 | if ( fitresult != 0 ){ | 
| 794 | if ( debug ) printf(" The fit failed, no integrals calculation and asymm is set to -1. \n"); | 
| 795 | asymm = -1.; | 
| 796 | } else { | 
| 797 | Int_t npp = 1000; | 
| 798 | double *xp=new double[npp]; | 
| 799 | double *wp=new double[npp]; | 
| 800 | lfit->CalcGaussLegendreSamplingPoints(npp,xp,wp,1e-12); | 
| 801 | Float_t imax = lfit->IntegralFast(npp,xp,wp,0.,tmax); | 
| 802 | //    Float_t imax = lfit->Integral(0.,tmax); | 
| 803 | if ( debug ) printf(" Integral till maximum (%f): %f \n",tmax,imax); | 
| 804 | Int_t np = 1000; | 
| 805 | double *x=new double[np]; | 
| 806 | double *w=new double[np]; | 
| 807 | lfit->CalcGaussLegendreSamplingPoints(np,x,w,1e-12); | 
| 808 | Float_t i10max = lfit->IntegralFast(np,x,w,0.,10.*tmax); | 
| 809 | delete x; | 
| 810 | delete w; | 
| 811 | delete xp; | 
| 812 | delete wp; | 
| 813 | //    Float_t i10max = lfit->Integral(0.,10.*tmax); | 
| 814 | if ( debug ) printf(" Integral: %f \n",i10max); | 
| 815 | // | 
| 816 | if ( i10max != imax ){ | 
| 817 | asymm = imax / (i10max-imax); | 
| 818 | } else { | 
| 819 | if ( debug ) printf(" i10max == imax, asymm undefined\n"); | 
| 820 | asymm = -2.; | 
| 821 | }; | 
| 822 | //lfit->Integral(0.,tmax)/(lfit->Integral(0.,10.*tmax)-lfit->Integral(0.,tmax)); | 
| 823 | if ( debug ) printf(" Asymmetry has been calculated \n"); | 
| 824 | }; | 
| 825 | // | 
| 826 | if ( draw ){ | 
| 827 | // | 
| 828 | tc->cd(); | 
| 829 | //    gStyle->SetOptStat(11111); | 
| 830 | tc->SetTitle(); | 
| 831 | th->SetTitle(""); | 
| 832 | th->SetName(""); | 
| 833 | th->SetMarkerStyle(20); | 
| 834 | // axis titles | 
| 835 | th->SetXTitle("Depth [X0]"); | 
| 836 | th->SetYTitle("Energy [MIP]"); | 
| 837 | th->DrawCopy("Perror"); | 
| 838 | lfit->Draw("same"); | 
| 839 | tc->Modified(); | 
| 840 | tc->Update(); | 
| 841 | // | 
| 842 | gStyle->SetLabelSize(0); | 
| 843 | gStyle->SetNdivisions(1,"XY"); | 
| 844 | // | 
| 845 | }; | 
| 846 | // | 
| 847 | delete lfit; | 
| 848 | // | 
| 849 | }; | 
| 850 |  | 
| 851 | void CaloLong::Draw(){ | 
| 852 | // | 
| 853 | Process(); | 
| 854 | Draw(-1); | 
| 855 | }; | 
| 856 |  | 
| 857 | void CaloLong::Draw(Int_t view){ | 
| 858 | // | 
| 859 | Int_t minv = 0; | 
| 860 | Int_t maxv = 0; | 
| 861 | // | 
| 862 | if ( view == -1 ){ | 
| 863 | maxv = -1; | 
| 864 | } else { | 
| 865 | minv = view; | 
| 866 | maxv = view+1; | 
| 867 | }; | 
| 868 | // | 
| 869 | Process(); | 
| 870 | // | 
| 871 | gStyle->SetLabelSize(0.04); | 
| 872 | gStyle->SetNdivisions(510,"XY"); | 
| 873 | // | 
| 874 | if ( maxv != -1 ){ | 
| 875 | for (Int_t v=minv; v<maxv;v++){ | 
| 876 | TString hid = Form("clongv%i",v); | 
| 877 | TCanvas *tc  = dynamic_cast<TCanvas*>(gDirectory->FindObject(hid)); | 
| 878 | if ( tc ){ | 
| 879 | //       tc->Clear(); | 
| 880 | } else { | 
| 881 | tc = new TCanvas(hid,hid); | 
| 882 | }; | 
| 883 | // | 
| 884 | TString thid = Form("hlongv%i",v); | 
| 885 | TH1F *th  = dynamic_cast<TH1F*>(gDirectory->FindObject(thid)); | 
| 886 | if ( th ) th->Delete(); | 
| 887 | //         th->Clear(); | 
| 888 | //         th->Reset(); | 
| 889 | //        } else { | 
| 890 | th = new TH1F(thid,thid,22,-0.5,21.5); | 
| 891 | //        }; | 
| 892 | tc->cd(); | 
| 893 | // | 
| 894 | for (Int_t st=0;st<22;st++){ | 
| 895 | th->Fill(st,eplane[v][st]); | 
| 896 | }; | 
| 897 | th->Draw(); | 
| 898 | tc->Modified(); | 
| 899 | tc->Update(); | 
| 900 | }; | 
| 901 | } else { | 
| 902 | // | 
| 903 | TString hid = Form("clongvyvx"); | 
| 904 | TCanvas *tc  = dynamic_cast<TCanvas*>(gDirectory->FindObject(hid)); | 
| 905 | if ( tc ){ | 
| 906 | } else { | 
| 907 | tc = new TCanvas(hid,hid); | 
| 908 | }; | 
| 909 | // | 
| 910 | TString thid = Form("hlongvyvx"); | 
| 911 | TH1F *th  = dynamic_cast<TH1F*>(gDirectory->FindObject(thid)); | 
| 912 | if ( th ) th->Delete(); | 
| 913 | th = new TH1F(thid,thid,44,-0.5,43.5); | 
| 914 | tc->cd(); | 
| 915 | Int_t pp=0; | 
| 916 | for (Int_t st=0;st<22;st++){ | 
| 917 | for (Int_t v=1; v>=0;v--){ | 
| 918 | // | 
| 919 | th->Fill(pp,eplane[v][st]); | 
| 920 | // | 
| 921 | pp++; | 
| 922 | }; | 
| 923 | }; | 
| 924 | th->Draw(); | 
| 925 | tc->Modified(); | 
| 926 | tc->Update(); | 
| 927 | }; | 
| 928 | // | 
| 929 | gStyle->SetLabelSize(0); | 
| 930 | gStyle->SetNdivisions(1,"XY"); | 
| 931 | // | 
| 932 | }; | 
| 933 |  | 
| 934 | void CaloLong::Delete(){ | 
| 935 | Clear(); | 
| 936 | //delete this; | 
| 937 | }; |