ATLAS Offline Software
Loading...
Searching...
No Matches
dqm_algorithms::MDTMultiplicity Class Reference

#include <MDTMultiplicity.h>

Inheritance diagram for dqm_algorithms::MDTMultiplicity:
Collaboration diagram for dqm_algorithms::MDTMultiplicity:

Public Member Functions

 MDTMultiplicity ()
virtual ~MDTMultiplicity ()
virtual dqm_core::Algorithm * clone ()
virtual dqm_core::Result * execute (const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
virtual void printDescription (std::ostream &out)

Private Attributes

std::string m_name

Detailed Description

Definition at line 15 of file MDTMultiplicity.h.

Constructor & Destructor Documentation

◆ MDTMultiplicity()

dqm_algorithms::MDTMultiplicity::MDTMultiplicity ( )

Definition at line 35 of file MDTMultiplicity.cxx.

36 : m_name("MDTmultiplicity")
37{
38 dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
39}

◆ ~MDTMultiplicity()

dqm_algorithms::MDTMultiplicity::~MDTMultiplicity ( )
virtual

Definition at line 42 of file MDTMultiplicity.cxx.

43{
44}

Member Function Documentation

◆ clone()

dqm_core::Algorithm * dqm_algorithms::MDTMultiplicity::clone ( )
virtual

Definition at line 48 of file MDTMultiplicity.cxx.

49{
50 return new MDTMultiplicity(*this);
51}

◆ execute()

dqm_core::Result * dqm_algorithms::MDTMultiplicity::execute ( const std::string & name,
const TObject & data,
const dqm_core::AlgorithmConfig & config )
virtual

Definition at line 55 of file MDTMultiplicity.cxx.

56{
57
58 const TH1 * hist;
59 const TH1 * ref;
60
61 if( object.IsA()->InheritsFrom( "TH1" ) ) {
62 hist = static_cast<const TH1*>(&object);
63 if (hist->GetDimension() >= 2 ){
64 throw dqm_core::BadConfig( ERS_HERE, name, "dimension >= 2 " );
65 }
66 } else {
67 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
68 }
69
70 //Get Reference Histo
71
72 try {
73 ref = static_cast<const TH1*>( config.getReference() );
74 }
75 catch ( dqm_core::Exception & ex ) {
76 throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
77 }
78 if (hist->GetDimension() != ref->GetDimension() ) {
79 throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different dimension!" );
80 }
81
82 //Get Parameters and Thresholds
83 double minstat;
84 double thresh_on_difference=75;
85 double thresh_on_peak_content=15;
86 //double peak_number=2;
87 double pos1=3;
88 double pos2=6;
89 double pos3=-1;
90 double greenTh=1;
91 double redTh=2;
92 double ref_y_n=1;
93
94 try {
95 minstat = dqm_algorithms::tools::GetFirstFromMap("MinStat", config.getParameters(), 100);
96 thresh_on_difference = dqm_algorithms::tools::GetFirstFromMap("IsolationThresh", config.getParameters(), 75);
97 thresh_on_peak_content = dqm_algorithms::tools::GetFirstFromMap("StatisticThresh", config.getParameters(), 15);
98 //peak_number = dqm_algorithms::tools::GetFirstFromMap("NumberOfPeaks", config.getParameters());
99 pos1 = dqm_algorithms::tools::GetFirstFromMap("FirstPeakPosition", config.getParameters(), 4);
100 pos2 = dqm_algorithms::tools::GetFirstFromMap("SecondPeakPosition", config.getParameters(), 8);
101 pos3 = dqm_algorithms::tools::GetFirstFromMap("ThirdPeakPosition", config.getParameters(), -1);
102 ref_y_n = dqm_algorithms::tools::GetFirstFromMap("UseRef", config.getParameters(), 0);
103 redTh = dqm_algorithms::tools::GetFromMap( "PeakShift", config.getRedThresholds());
104 greenTh = dqm_algorithms::tools::GetFromMap( "PeakShift", config.getGreenThresholds() );
105 }
106 catch ( dqm_core::Exception & ex ) {
107 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
108 }
109
110 //Check of statistics
111 if (hist->GetEntries() < minstat ) {
112 ERS_INFO("Histogram does not satisfy MinStat requirement " <<hist->GetName());
113 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
114 result->tags_["InsufficientEntries"] = hist->GetEntries();
115 return result;
116 }
117 ERS_DEBUG(1,"Statistics: "<< hist->GetEntries()<< " entries ");
118
119 //Algo
120 unsigned int i=0;
121 unsigned int k=0;
122 std::vector<double> derivate;
123 std::vector<double> peak_candidate;
124 std::vector<double> peak;
125 std::vector<double> valley;
126
127 std::vector<double> derivate_ref;
128 std::vector<double> peak_candidate_ref;
129 std::vector<double> peak_ref;
130 std::vector<double> valley_ref;
131
132 //Filling vector of derivate
133 for(i=1;i<=(unsigned int)hist->GetNbinsX();i++){
134 if((i+1)<=(unsigned int)hist->GetNbinsX()) derivate.push_back(hist->GetBinContent(i+1)-hist->GetBinContent(i));
135 if((i+1)<=(unsigned int)ref->GetNbinsX() && ref_y_n==1) derivate_ref.push_back(ref->GetBinContent(i+1)-ref->GetBinContent(i));
136 };
137
138 i=0;
139
140 //Look for peaks and valley
141 Double_t highest_peak=0;
142 Double_t peak_content;
143 Double_t first_valley_content;
144 Double_t second_valley_content;
145 Double_t highest_peak_ref=0;
146 Double_t peak_content_ref;
147 Double_t first_valley_content_ref;
148 Double_t second_valley_content_ref;
149
150 if(derivate[0]>=0) valley.push_back(0);
151 if(derivate[0]<0){
152 peak_candidate.push_back(0);
153 highest_peak=hist->GetBinContent(1);
154 }
155 if(ref_y_n==1){
156 if(derivate_ref[0]>=0) valley_ref.push_back(0);
157 if(derivate_ref[0]<0){
158 peak_candidate_ref.push_back(0);
159 highest_peak_ref=ref->GetBinContent(1);
160 }
161 };
162
163 for(i=0;i<(derivate.size()-1);i++){
164 if(derivate[i]>0 && derivate[i+1]<0){
165 peak_candidate.push_back(i+1);
166 peak_content=hist->GetBinContent(i+2);
167 if(peak_content>highest_peak) highest_peak=peak_content;
168 }else if(derivate[i]<0 && derivate[i+1]>0){
169 valley.push_back(i+1);
170 };
171
172 if(ref_y_n==1){
173 if(derivate_ref[i]>0 && derivate_ref[i+1]<0){
174 peak_candidate_ref.push_back(i+1);
175 peak_content_ref=ref->GetBinContent(i+2);
176 if(peak_content_ref>highest_peak_ref) highest_peak_ref=peak_content_ref;
177 }else if(derivate_ref[i]<0 && derivate_ref[i+1]>0){
178 valley_ref.push_back(i+1);
179 };
180 };
181 };
182
183 valley.push_back(hist->GetNbinsX());
184 valley_ref.push_back(hist->GetNbinsX());
185
186 //Peak Definition (isolation and high statistic)
187 i=0;
188
189 for(i=0;i<peak_candidate.size();i++){
190 peak_content=hist->GetBinContent((Int_t)peak_candidate[i]+1);
191 first_valley_content=hist->GetBinContent((Int_t)valley[i]+1);
192 second_valley_content=hist->GetBinContent((Int_t)valley[i+1]+1);
193 if(first_valley_content==0) first_valley_content=1;
194 if(second_valley_content==0) second_valley_content=1;
195
196 if((first_valley_content<=second_valley_content) && (peak_content>(thresh_on_peak_content*highest_peak/100)) && (first_valley_content<(thresh_on_difference*peak_content/100))){
197 peak.push_back(peak_candidate[i]);
198 }else if((first_valley_content>second_valley_content) && (peak_content>(thresh_on_peak_content*highest_peak/100)) && (second_valley_content<(thresh_on_difference*peak_content/100))){
199 peak.push_back(peak_candidate[i]);
200 };
201 };
202
203 i=0;
204 if(ref_y_n==1){
205 for(i=0;i<peak_candidate_ref.size();i++){
206 peak_content_ref=ref->GetBinContent((Int_t)peak_candidate_ref[i]+1);
207 first_valley_content_ref=ref->GetBinContent((Int_t)valley_ref[i]+1);
208 second_valley_content_ref=ref->GetBinContent((Int_t)valley_ref[i+1]+1);
209 if(first_valley_content_ref==0) first_valley_content_ref=1;
210 if(second_valley_content_ref==0) second_valley_content_ref=1;
211
212 if((first_valley_content_ref<=second_valley_content_ref) && (peak_content_ref>(thresh_on_peak_content*highest_peak_ref/100)) && (first_valley_content_ref<(thresh_on_difference*peak_content_ref/100))){
213 peak_ref.push_back(peak_candidate_ref[i]);
214 }else if((first_valley_content_ref>second_valley_content_ref) && (peak_content_ref>(thresh_on_peak_content*highest_peak_ref/100)) && (second_valley_content_ref<(thresh_on_difference*peak_content_ref/100))){
215 peak_ref.push_back(peak_candidate_ref[i]);
216 };
217 };
218 };
219
220 //Result
221
222 dqm_core::Result* result = new dqm_core::Result();
223
224 double count=0;
225 //double first_peak=-1;
226 //double second_peak=-1;
227 //double third_peak=-1;
228 double diff1=9999;
229 double diff2=9999;
230 double diff3=9999;
231
232 if(ref_y_n==0){
233 i=0;
234 for(i=0;i<peak.size();i++){
235 if(std::abs(peak[i]-pos1)<=diff1){
236 //first_peak=i;
237 diff1=std::abs(peak[i]-pos1);
238 };
239 if(std::abs(peak[i]-pos2)<=diff2){
240 //second_peak=i;
241 diff2=std::abs(peak[i]-pos2);
242 };
243 if(std::abs(peak[i]-pos3)<=diff3 && pos3>0){
244 //third_peak=i;
245 diff3=std::abs(peak[i]-pos3);
246 };
247 };
248 //if(peak.size() != peak_number) count = 10;
249 if(diff1>greenTh) count++;
250 if(diff2>greenTh) count++;
251 if(diff3>greenTh && pos3>0) count++;
252 if(diff1>redTh) count+=2;
253 if(diff2>redTh) count+=2;
254 if(diff3>redTh && pos3>0) count+=2;
255
256 result->tags_["00-Number_of_found_peaks"] = peak.size();
257 for(size_t p=0; p<peak.size(); p++){
258 result->tags_[std::format ("{:02d}-Peak", p+1)] = peak[p];
259 };
260 };
261
262 if(ref_y_n==1){
263 i=0;
264 k=0;
265 std::vector<double> diff;
266 std::vector<double> peak_correspondence;
267 for(i=0;i<peak.size();i++){
268 diff1=9999;
269 peak_correspondence.push_back(99999);
270 diff.push_back(99999);
271 for(k=0;k<peak_ref.size();k++){
272 if(std::abs(peak[i]-peak_ref[k])<=diff1){
273 peak_correspondence[i]=k;
274 diff[i]=std::abs(peak[i]-peak_ref[k]);
275 diff1=std::abs(peak[i]-peak_ref[k]);
276 };
277 };
278 };
279 i=0;
280 for(i=0;i<peak.size();i++){
281 if(diff[i]>greenTh) count++;
282 if(diff[i]>redTh) count+=2;
283 };
284
285 result->tags_["a-00-Number_of_found_peaks"] = peak.size();
286 result->tags_["b-00-Number_of_found_peaks_ref"] = peak_ref.size();
287
288 for(size_t p=0; p<peak.size(); p++){
289 result->tags_[std::format ("a-{:02d}Peak", p+1)] = peak[p];
290 };
291 for(size_t p=0; p<peak_ref.size(); p++){
292 result->tags_[std::format ("b-{:02d}Peak", p+1)] = peak_ref[p];
293 };
294 };
295
296 if(count==0){
297 result->status_ = dqm_core::Result::Green;
298 };
299 if(count>=1 && count<3){
300 result->status_ = dqm_core::Result::Yellow;
301 };
302 if(count>=3){
303 result->status_ = dqm_core::Result::Red;
304 };
305
306 // Return the result
307 return result;
308}
const boost::regex ref(r_ef)
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
#define IsA
Declare the TObject style functions.

◆ printDescription()

void dqm_algorithms::MDTMultiplicity::printDescription ( std::ostream & out)
virtual

Definition at line 312 of file MDTMultiplicity.cxx.

312 {
313 std::string message;
314 message += "\n";
315 message += "Algorithm: \"" + m_name + "\"\n";
316 message += "Description: it look for peaks in the histogram and it compare their position with user defined position or with reference histogram peak position. The algorithm define a peak first looking for the higher statistic bin then it look for other bins with at last a user defined percent of the entrance of the maximum bin \n";
317 message += "Green/Red Thresh: PeakShift: the number of bins tollerated for the shift of a peak\n";
318 message += "Mandatory Params: MinStat: minimum statistical requirement\n";
319 message += " IsolationThresh: The alghorithm need it to define a peak. It define the minumum difference,in percent, between the peak entrance and the closer 'valley' entrance(valley is defined as the bin where the derivate change sign from negative to positive).\n";
320 message += " StatisticThresh: The minimum bin entrance required expressed in percent compared with the maximum bin. If the bin has less then this percent of entrance it can't be defined as a peak.\n";
321 message += " FirstPeakPosition: Mandatory in no reference mode. It is the position expected for the first peak\n";
322 message += " SecondPeakPosition: Mandatory in no reference mode. It is the position expected for the second peak\n";
323 message += " ThirdPeakPosition: Mandatory in no reference mode. It is the position expected for the third peak\n";
324 message += " UseRef: 1 to use a reference histogram, 0 to use user definition for the peaks position without a reference comparison\n";
325 message += "Optional Params: NumberOfPeaks: In the no reference mode it define how many peaks the algorithm has to looking for. if it find more then this number of peack it set the flag red\n";
326 out << message;
327}

Member Data Documentation

◆ m_name

std::string dqm_algorithms::MDTMultiplicity::m_name
private

Definition at line 27 of file MDTMultiplicity.h.


The documentation for this class was generated from the following files: