--- calo/flight/CaloPreSampler/src/CaloPreSampler.cpp 2007/07/20 08:27:45 1.1 +++ calo/flight/CaloPreSampler/src/CaloPreSampler.cpp 2009/09/10 12:52:51 1.14 @@ -12,7 +12,7 @@ */ CaloPreSampler::CaloPreSampler(){ Clear(); -}; +} CaloPreSampler::CaloPreSampler(PamLevel2 *l2p){ // @@ -30,12 +30,20 @@ cstrip = new CaloStrip(false); // c1 = new CaloLevel1(); pcalo = new CaloLevel2(); - N = 3; + N = 4; + NC = 22-N; debug = false; sel = true; cont = false; emulate18 = true; simulation = false; + withtrk = true; + rigdefault = 50.; + nox = false; + noy = false; + forcecalo = false; + forcefitmode = -1; + memset(mask,0,2*22*sizeof(Int_t)); // Clear(); // @@ -62,13 +70,49 @@ printf(" Reading magnetic field maps at %s\n",(q4->PATH+q4->NAME).Data()); trk->LoadField(q4->PATH+q4->NAME); // -}; +} + +void CaloPreSampler::SetNoWpreSampler(Int_t n){ + if ( NC+n < 23 ){ + N = n; + } else { + printf(" ERROR! Calorimeter is made of 22 W planes\n"); + printf(" you are giving N presampler = %i and N calo = %i \n",n,NC); + printf(" WARNING: using default values NWpre = 4, NWcalo = 18\n"); + NC = 18; + N = 4; + }; +} + +void CaloPreSampler::SetNoWcalo(Int_t n){ + if ( N+n < 23 ){ + NC = n; + } else { + printf(" ERROR! Calorimeter is made of 22 W planes\n"); + printf(" you are giving N W presampler = %i and N W calo = %i \n",N,n); + printf(" WARNING: using default values NWpre = 4, NWcalo = 18\n"); + NC = 18; + N = 4; + }; +} + +void CaloPreSampler::SplitInto(Int_t NoWpreSampler, Int_t NoWcalo){ + this->SetNoWcalo(0); + this->SetNoWpreSampler(0); + if ( NoWpreSampler < NoWcalo ){ + this->SetNoWpreSampler(NoWpreSampler); + this->SetNoWcalo(NoWcalo); + } else { + this->SetNoWcalo(NoWcalo); + this->SetNoWpreSampler(NoWpreSampler); + }; +} void CaloPreSampler::Clear(){ // pcalo->Clear(); // -}; +} void CaloPreSampler::Print(){ // @@ -84,17 +128,19 @@ printf(" pre-sampler planes :.. %i\n",N); printf(" pcalo->qtot :.. %f\n",pcalo->qtot); printf(" pcalo->nstrip :.. %i\n",pcalo->nstrip); - printf(" pcalo->track0->qtrack :.. %f\n",pcalo->GetCaloTrkVar(0)->qtrack); - printf(" pcalo->track0->dX0l :.. %f\n",pcalo->GetCaloTrkVar(0)->dX0l); + if ( pcalo->ntrk() > 0 ){ + printf(" pcalo->track0->qtrack :.. %f\n",pcalo->GetCaloTrkVar(0)->qtrack); + printf(" pcalo->track0->dX0l :.. %f\n",pcalo->GetCaloTrkVar(0)->dX0l); + }; printf("========================================================================\n"); // -}; +} void CaloPreSampler::Delete(){ Clear(); delete pcalo; //delete this; -}; +} void CaloPreSampler::Process(){ @@ -105,9 +151,23 @@ return; }; // + // Clear structures used to communicate with fortran + // + event->ClearStructs();//ELENA + if ( forcefitmode > 0 ){ + if ( forcefitmode != 1000 && forcefitmode != 1001 && forcefitmode != 1002 ){ + printf(" ERROR! forcefitmode=%i \n Use forcefitmode = 1000 for fit mode 0, 1001 fit mode 1, 1002 fit mode 3\n",forcefitmode); + forcefitmode = -1; + } else { + event->clevel2->fmode[0] = forcefitmode; + event->clevel2->fmode[1] = forcefitmode; + }; + }; + // Bool_t newentry = false; // if ( L2->IsORB() ){ + if ( debug ) printf(" I am here, we have orbital infos \n"); if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime || sel != ssel ){ newentry = true; OBT = L2->GetOrbitalInfo()->OBT; @@ -129,9 +189,9 @@ Int_t S11 = 0; Float_t tmptrigty = -1.; Bool_t trackanyway = true; - Float_t rigdefault = 50.; + // Float_t rigdefault = 50.; Bool_t hZn = true; - Bool_t withtrk = true; + // Bool_t withtrk = true; Bool_t st = true; Int_t ntrkentry = 0; TrkLevel2 *trk = L2->GetTrkLevel2(); @@ -151,6 +211,7 @@ if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -2 ) m2 = true; if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -3 ) m3 = true; }; + if ( !withtrk ) m3 = true; // if ( debug ) printf(" Fill estrip matrix needed to calculate variables \n"); // @@ -165,13 +226,22 @@ // mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip); // + // Mask x or y view if nox and/or noy are true (default false) + // + if ( mask[view][plane] ) mip = 0.; + if ( nox && view == 0 ) mip = 0.; + if ( noy && view == 1 ) mip = 0.; + // + if ( emulate18 && view == 0 && plane == 18 ) mip = 0.; + // // Selection mode: fill the matrix only for plane < (22 - N) REMEMBER N = number of W planes to be used as presampler, ie if N = 2 then we want to use planes from 0 to 19 // included so plane < (22 - 2) // if ( sel ){ if ( plane < (22 - N) ){ // - if ( emulate18 && plane == (18 - N) ) mip = 0.; + if ( emulate18 && plane == (18 - N) && view == 0 ) mip = 0.; + if ( plane >= NC ) mip = 0.; event->clevel1->estrip[strip][plane][view] = mip; // }; @@ -182,7 +252,8 @@ if ( cont ){ if ( plane >= N ){ // - if ( emulate18 && plane == (18 + N) ) mip = 0.; + if ( emulate18 && plane == (18 + N) && view == 0 ) mip = 0.; + if ( (plane-N) >= NC ) mip = 0.; event->clevel1->estrip[strip][(plane-N)][view] = mip; // }; @@ -226,7 +297,8 @@ // // use only N W planes // - event->clevel1->npla = 22-N; + // event->clevel1->npla = 22-N; + event->clevel1->npla = NC; // S3 = 0; S2 = 0; @@ -246,6 +318,14 @@ // event->clevel1->good2 = 1; // + // copy variables calculated during calibration process which is skipped here... + // + event->clevel2->good = L2->GetCaloLevel2()->good; + memcpy(event->clevel2->perr,L2->GetCaloLevel2()->perr,sizeof(L2->GetCaloLevel2()->perr)); + memcpy(event->clevel2->swerr,L2->GetCaloLevel2()->swerr,sizeof(L2->GetCaloLevel2()->swerr)); + memcpy(event->clevel2->crc,L2->GetCaloLevel2()->crc,sizeof(L2->GetCaloLevel2()->crc)); + event->clevel2->selftrigger = L2->GetCaloLevel2()->selftrigger; + // // Calculate variables common to all tracks (qtot, nstrip, etc.) // if ( debug ) printf("1 Call GetCommonVar() \n"); @@ -309,7 +389,7 @@ // conditions are: 0) no track from the tracker 1) we have a track fit both in x and y 2) no problems with calo for this event 3) no selftrigger event // // if ( trackanyway && !filled && event->clevel2->npcfit[0] >= 2 && event->clevel2->npcfit[1] >= 2 && event->clevel2->good != 0 && event->clevel2->trigty < 2. ){ - if ( trackanyway && m3 ){ + if ( (trackanyway && m3) || forcecalo ){ if ( debug ) printf(" Event with a track not fitted by the tracker \n"); // // Disable "track mode" in the fortran routine @@ -441,14 +521,62 @@ if ( debug ) printf(" Selftrigger: problems with event \n"); }; }; - // - // Clear structures used to communicate with fortran - // - event->ClearStructs(); +// // +// // Clear structures used to communicate with fortran +// // +// event->ClearStructs(); +// ELENA: moved @ beginning // // // if ( debug ) this->Print(); if ( debug ) printf(" exit \n"); // -}; +} + +// +// Method to add a calorimeter track, evaluated around a tracker track defined by a status vector. +// (can be used to evaluate the calorimeter track around an arbitrary axis, by setting the status vector with zero deflection ) +// +// +CaloTrkVar* CaloPreSampler::AddCaloTrkVar(float *al,int trktag){ + + int ntrkentry = pcalo->ntrk(); + // + for (Int_t nt=0; nt < ntrkentry; nt++){ + if( pcalo->GetCaloTrkVar(nt)->trkseqno == trktag){ + cout << " CaloTrkVar* CaloPreSampler::AddCaloTrkVar(float *al,int trktag)"< trktag = "<clevel1->good2 = 1; //is a trk track + event->clevel1->trkchi2 = 0; + event->clevel1->hzn = 0; + // + // Copy the alpha vector in the input structure + // + for (Int_t e = 0; e < 5 ; e++){ + event->clevel1->al_p[e][0] = al[e]; + }; + // + // Get tracker related variables for this track + // + if ( debug ) printf("track %i Call GetTrkVar() \n",trktag); + event->GetTrkVar(); + if ( debug ) printf(" event->clevel2->dX0l %f \n",event->clevel2->dX0l); + // + // Save tracker track sequence number + // + event->trkseqno = trktag; + // + // Copy values in the class ca from the structure clevel2 + // + if ( debug ) printf("track %i Call FillTrkVar() \n",trktag); + event->FillTrkVar(pcalo,ntrkentry); + + return pcalo->GetCaloTrkVar(ntrkentry); + + +};//ELENA