PamCut: PamCutBase/PamCutBase.cpp Source File

- Main Page
- Classes
- Files

- File List
- File Members

# PamCutBase/PamCutBase.cpp

Go to the documentation of this file.

    00001 /*
    00002  * PamCutBase.cpp
    00003  *
    00004  *  Created on: 12-feb-2009
    00005  *      Author: Nicola Mori
    00006  */
    00007
    00010 #include "PamCutBase.h"
    00011
    00012 /* ************** *
    00013  *     PAMCUT
    00014  * ************** */
    00015 int PamCut::ApplyCut(PamLevel2 *event) {
    00016
    00017   _nEv++;
    00018   int result = Check(event);
    00019   if (result == CUTOK) {
    00020     _nGood++;
    00021     OnGood(event);
    00022   }
    00023   else {
    00024     OnBad(event, result);
    00025   }
    00026   return result;
    00027
    00028 }
    00029
    00030 void PamCut::Process(PamLevel2 *events, ULong_t firstEvent, ULong_t lastEvent) {
    00031
    00032   // Check the range of events to analyze
    00033   if (firstEvent > lastEvent) {
    00034     return;
    00035   }
    00036   if (firstEvent < 0 || lastEvent > events->GetEntries() - 1) {
    00037     return;
    00038   }
    00039
    00040   // Prepare the counters for the new analysis
    00041   Setup(events);
    00042
    00043   // Apply the cuts
    00044   for (ULong_t iev = firstEvent; iev < lastEvent + 1; iev++) {
    00045     events->GetEntry(iev);
    00046     ApplyCut(events);
    00047   }
    00048
    00049   // Closes the analysis
    00050   Finalize();
    00051
    00052 }
    00053 void PamCut::Setup(PamLevel2 *events) {
    00054   _nEv = _nGood = 0;
    00055 }
    00056
    00057 const char* PamCut::GetName() const {
    00058   return _cutName;
    00059 }
    00060
    00061 void PamCut::SetName(const char *newName) {
    00062   _cutName = newName;
    00063 }
    00064
    00065 PamCut& PamCut::operator=(const PamCut &rightValue) {
    00066   _cutName = rightValue._cutName;
    00067   return *this;
    00068 }
    00069
    00070 /* ************************ *
    00071  *     PAMCUTCOLLECTION
    00072  * ************************ */
    00073
    00074 void PamCutCollection::AddCut(PamCut &cut) {
    00075   _cuts.push_back(&cut);
    00076 }
    00077
    00078 int PamCutCollection::Check(PamLevel2 *event) {
    00079
    00080   // Apply the cuts
    00081   if (_cuts.size() == 0) {
    00082     return CUTOK;
    00083   }
    00084
    00085   for (unsigned int icut = 0; icut < _cuts.size(); icut++) {
    00086     if (_cuts[icut]->Check(event) != CUTOK) {
    00087       return icut;
    00088     }
    00089   }
    00090
    00091   return CUTOK;
    00092 }
    00093
    00094 int PamCutCollection::ApplyCut(PamLevel2 *event) {
    00095
    00096   _nEv++;
    00097   // Apply the cuts
    00098   if (_cuts.size() == 0) {
    00099     _nGood++;
    00100     OnGood(event);
    00101     return CUTOK;
    00102   }
    00103
    00104   for (unsigned int icut = 0; icut < _cuts.size(); icut++) {
    00105     if (_cuts[icut]->ApplyCut(event) != CUTOK) {
    00106       OnBad(event, icut);
    00107       return icut;
    00108     }
    00109   }
    00110
    00111   _nGood++;
    00112   OnGood(event);
    00113   return CUTOK;
    00114 }
    00115
    00116 PamCut *PamCutCollection::GetCut(unsigned int iCut) {
    00117   if (_cuts.size() == 0)
    00118     return NULL;
    00119   if (iCut < 0 || iCut > _cuts.size() - 1)
    00120     return NULL;
    00121   else
    00122     return _cuts[iCut];
    00123 }
    00124
    00125 unsigned int PamCutCollection::GetSize() {
    00126   return (unsigned int) _cuts.size();
    00127
    00128 }
    00129
    00130 PamCutCollection& PamCutCollection::operator=(const PamCutCollection &rightValue) {
    00131
    00132   PamCut::operator=(rightValue);
    00133   _cuts = rightValue._cuts;
    00134   return *this;
    00135 }
    00136
    00137 void PamCutCollection::Setup(PamLevel2 *events) {
    00138
    00139   PamCut::Setup(events);
    00140
    00141   for (unsigned int i = 0; i < GetSize(); i++) {
    00142     _cuts[i]->Setup(events);
    00143   }
    00144 }
    00145
    00146 void PamCutCollection::Finalize() {
    00147
    00148   // PamCut::Finalize() is currently void, but in future it could contain something, so it's good to place a call here.
    00149   PamCut::Finalize();
    00150
    00151   for (unsigned int i = 0; i < GetSize(); i++) {
    00152     _cuts[i]->Finalize();
    00153   }
    00154 }