PamCut: TofCuts/TofPatternCut/TofPatternCut.cpp Source File

- Main Page
- Classes
- Files

- File List
- File Members

# TofCuts/TofPatternCut/TofPatternCut.cpp

Go to the documentation of this file.

    00001 /*
    00002  * TofPatternCut.cpp
    00003  *
    00004  *  Created on: 12-mar-2009
    00005  *      Author: Elena Vannuccini
    00006  */
    00007
    00010 #include "TofPatternCut.h"
    00011
    00012 int TofPatternCut::Check(PamLevel2 *event) {
    00013
    00014   if (!event)
    00015     return (0);
    00016   //
    00017   ToFLevel2 *tofl2 = event->GetToFLevel2();
    00018   if (!tofl2)
    00019     return (0);
    00020   ToFTrkVar *tof = 0;
    00021   if (!_standalone && _notrk >= 0 && _notrk < event->GetTrkLevel2()->GetNTracks())
    00022     tof = event->GetTrack(_notrk)->GetToFTrack();
    00023   if (_standalone)
    00024     tof = event->GetToFStoredTrack(-1);
    00025   if (!tof)
    00026     return (0);
    00027
    00028 #ifdef DEBUGPAMCUT
    00029     cout << ">>> TofPatternCut CHECK <<<" << endl;
    00030 #endif
    00031
    00032   bool TOF__OK = false;
    00033
    00034 #ifdef DEBUGPAMCUT
    00035     cout << "Check topology:" << endl;
    00036     for (int ip = 0; ip < 6; ip++)
    00037       cout << "plane " << ip << " n.hit paddles " << tofl2->GetNHitPaddles(ip) << endl;
    00038     for (int ip = 0; ip < 6; ip++)
    00039       cout << "plane " << ip << " n.hit PMTs outside track " << GetNHitPMTsOutsideTrack(event, ip) << endl;
    00040 #endif
    00041
    00042   // -----------------------------------------
    00043   // at least one hit paddle on both S1 and S2
    00044   // -----------------------------------------
    00045   if (
    00046   //-----------------------------------
    00047   // not more than 1 paddle per layer
    00048   //-----------------------------------
    00049   tofl2 && tofl2->GetNHitPaddles(0) <= 1 && //S11
    00050       tofl2->GetNHitPaddles(1) <= 1 && //S12
    00051       tofl2->GetNHitPaddles(2) <= 1 && //S21
    00052       tofl2->GetNHitPaddles(3) <= 1 && //S22
    00053       //        tofl2->GetNHitPaddles(4) <= 1 && //S31
    00054       //        tofl2->GetNHitPaddles(5) <= 1 && //S32
    00055       //-----------------------------------
    00056       // at least 1 paddle per plane
    00057       //-----------------------------------
    00058       (tofl2->GetNHitPaddles(0) == 1 || tofl2->GetNHitPaddles(1) == 1) && //S1
    00059       (tofl2->GetNHitPaddles(2) == 1 || tofl2->GetNHitPaddles(3) == 1) && //S2
    00060       //        (tofl2->GetNHitPaddles(4)==1 || tofl2->GetNHitPaddles(5)==1) && //S3
    00061       //-----------------------------------
    00062       // n.hit pmts outside track
    00063       //-----------------------------------
    00064       //        GetHitPMTsOutsideTrack(event,0)<2 && //S11       //troppo (puo` succedere )
    00065       //        GetHitPMTsOutsideTrack(event,1)<2 && //S12
    00066       //        GetHitPMTsOutsideTrack(event,2)<2 && //S21
    00067       //        GetHitPMTsOutsideTrack(event,3)<2 && //S22
    00068       GetNHitPMTsOutsideTrack(event, 0) < 3 && //S11
    00069       GetNHitPMTsOutsideTrack(event, 1) < 3 && //S12
    00070       //        GetHitPMTsOutsideTrack(event,2)<3 && //S21
    00071       //        GetHitPMTsOutsideTrack(event,3)<3 && //S22
    00072       true)
    00073     TOF__OK = true;
    00074
    00075   if (!TOF__OK) {
    00076 #ifdef DEBUGPAMCUT
    00077       cout << "(((DISCARDED)))" << endl;
    00078 #endif
    00079     return (0);
    00080   };
    00081
    00082 #ifdef DEBUGPAMCUT
    00083     cout << "--> OK" << endl;
    00084     cout << "Check track concistency:" << endl;
    00085 #endif
    00086
    00087   // -----------------------------------------------
    00088   // the hit paddles MUST be associated to the track
    00089   // (in collaborazione con wolfgang)
    00090   // -----------------------------------------------
    00091   //
    00092   //  first build the map of hit PMTs along the track
    00093   //  and discard the event if there is an hit paddle,
    00094   //  but it is not the one associated to the track
    00095   //
    00096
    00097   int hitplane[] = { 0, 0, 0, 0, 0, 0 };
    00098   int hitpaddle[] = { -1, -1, -1, -1, -1, -1 };
    00099   for (Int_t ip = 0; ip < tof->npmttdc; ip++) {//loop over tdc hits associated to the track
    00100     Int_t iplane = -1;
    00101     Int_t ipaddle = -1;
    00102     Int_t ipmt = -1;
    00103     Int_t id = tof->pmttdc[ip];//pmt id
    00104     tofl2->GetPMTName(id, iplane, ipaddle, ipmt);
    00105     if (tof->tdcflag[ip] == 0) {
    00106       hitplane[iplane] = 1; //there is a true tdc signal associated to the track
    00107 #ifdef DEBUGPAMCUT
    00108       if (hitpaddle[iplane] >= 0 && hitpaddle[iplane] != ipaddle)
    00109         cout << "ORRORE!!!!" << endl;
    00110 #endif
    00111       hitpaddle[iplane] = ipaddle;//store the id of the paddle associated to the track
    00112       //
    00113       //
    00114       //
    00115       if (tofl2->GetNHitPaddles(iplane) > 0 && //if there is a hit paddle in this plane...
    00116           !tofl2->HitPaddle(iplane, hitpaddle[iplane]) && //... and the paddle associated to the track is not hit
    00117           true) {
    00118 #ifdef DEBUGPAMCUT
    00119           cout << "hit plane " << iplane << " -- track PMT " << hitpaddle[iplane] << " is not hit " << endl;
    00120           cout << "(((DISCARDED)))" << endl;
    00121 #endif
    00122         return (0);//discard the event
    00123       }
    00124     }
    00125   };
    00126   //
    00127   // hence check the planes with no PMTs associated to the track:
    00128   // the event is discarded if there is a hit paddle
    00129   //
    00130   for (int iplane = 0; iplane < 4; iplane++) {//loop over S11/S12/S21/S22
    00131     if (hitplane[iplane] == 0 && //if there are no PMTs associated to the track...
    00132         tofl2->GetNHitPaddles(iplane) > 0 && //...and the plane has hit paddles
    00133         true) {
    00134 #ifdef DEBUGPAMCUT
    00135         cout << "hit plane " << iplane << " has no PMTs associated to the track " << endl;
    00136         cout << "(((DISCARDED)))" << endl;
    00137 #endif
    00138       return (0);//discard the event
    00139     }
    00140   }
    00141
    00142   //
    00143   // forse non c'e` bisogno di tutto cio`?
    00144   //
    00145   //     for(int iplane=0; iplane<4; iplane++){//loop over S11/S12/S21/S22
    00146   //    //retrieve the id of the paddle traversed by the track
    00147   //    // (...there is some tolerance...)
    00148   //    int ipaddle = tofl2->GetPaddleIdOfTrack(tof->xtr_tof[iplane],tof->ytr_tof[iplane],iplane);
    00149   //    //check if the traversed paddle is hit
    00150   //    bool OK = true;
    00151   //    if(
    00152   //        tofl2->GetNHitPaddles(iplane)>0 &&//if there is a hit paddle in this plane...
    00153   //        !tofl2->HitPaddle(iplane,ipaddle) && //...and the paddle traversed by the track is not hit
    00154   //        true)OK = false;//..discard the event
    00155   //    /// hence try to recover some events...
    00156   //    if(
    00157   //        tofl2->GetNHitPaddles(iplane)>0 &&//if there is a hit paddle...
    00158   //        ipaddle==-1 &&//...and the track does not traverse any paddle...
    00159   //        tofl2->HitPaddle(iplane,hitpaddle[iplane]) &&//... BUT there are tdc signals belonging to a hit paddle
    00160   //        true)OK=true;//recover
    00161
    00162   //    if(!OK)return (0);
    00163
    00164   //     }
    00165
    00166   //    if( !TOF__OK )return (0);
    00167
    00168 #ifdef DEBUGPAMCUT
    00169     cout << "--> OK" << endl;
    00170 #endif
    00171
    00172   return CUTOK; //good pattern
    00173
    00174 }
    00175 //===========================================================
    00176 //
    00177 //
    00178 //
    00179 //
    00180 //
    00181 //===========================================================
    00182 int TofPatternCut::GetNHitPMTsOutsideTrack(PamLevel2 *event, int plane) {
    00183
    00184   if (!event)
    00185     return (0);
    00186   //
    00187   ToFLevel2 *tofl2 = event->GetToFLevel2();
    00188   if (!tofl2)
    00189     return (0);
    00190   ToFTrkVar *tof = 0;
    00191   if (!_standalone && _notrk >= 0 && _notrk < event->GetTrkLevel2()->GetNTracks())
    00192     tof = event->GetTrack(_notrk)->GetToFTrack();
    00193   if (_standalone)
    00194     tof = event->GetToFStoredTrack(-1);
    00195   if (!tof)
    00196     return (0);
    00197
    00198   int nn = 0;
    00199   //    cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
    00200   for (int ip = 0; ip < tofl2->npmt(); ip++) { //loop over ALL PMTs
    00201     Int_t iplane = -1;
    00202     Int_t ipaddle = -1;
    00203     Int_t ipmt = -1;
    00204     Int_t id = tofl2->GetToFPMT(ip)->pmt_id; //PMT id
    00205     tofl2->GetPMTName(id, iplane, ipaddle, ipmt);
    00206
    00207     if (iplane != plane)
    00208       continue;
    00209     //  cout << endl<<plane << " -- "<<id;
    00210     float tdc = tofl2->GetToFPMT(ip)->tdc;
    00211     if (tdc >= 4095.)
    00212       continue;
    00213     // spiegazione:
    00214     // quando c'e` adc pile-up, succede che un pmt abbia un segnale adc (adc<4095) ma NON tdc (tdc==4095),
    00215     // che e` il contrario di quanto avviene di solito. quindi, se nel livello 2 c'e` un pmt colpito
    00216     // e questo ha tdc==4095, implica che c'e` solo il segnale adc e che probabilmente non e` un vero segnale,
    00217     // ma e` il pile-up dell'evento precedente
    00218
    00219     // loop over TDC hits along the track
    00220     int iht = -1;
    00221     for (iht = 0; iht < tof->npmttdc; iht++)
    00222       if (id == tof->pmttdc[iht])
    00223         break; //match
    00224     if (iht >= 0 && iht < tof->npmttdc)
    00225       continue;
    00226     // loop over ADC hits along the track (credo sia inutile...)
    00227     //  int iha = -1;
    00228     //          for(iha=0; iha<tof->npmtadc; iha++)if(id==tof->pmtadc[iha])break; //match
    00229     //          if( iha>=0 && iha <tof->npmtadc )continue;
    00230     // get here if outside track
    00231     nn++;
    00232
    00233     //  cout << " OUTSIDE ";
    00234   }
    00235   return nn;
    00236
    00237 }
    00238