CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoRomanPot/RecoFP420/src/FP420ClusterMain.cc

Go to the documentation of this file.
00001 
00002 // File: FP420ClusterMain.cc
00003 // Date: 12.2006
00004 // Description: FP420ClusterMain for FP420
00005 // Modifications: 
00007 #include <vector>
00008 #include <iostream>
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011 
00012 #include "RecoRomanPot/RecoFP420/interface/FP420ClusterMain.h"
00013 #include "DataFormats/FP420Digi/interface/HDigiFP420.h"
00014 #include "DataFormats/FP420Cluster/interface/ClusterFP420.h"
00015 #include "RecoRomanPot/RecoFP420/interface/ClusterProducerFP420.h"
00016 #include "RecoRomanPot/RecoFP420/interface/ClusterNoiseFP420.h"
00017 
00018 #include "CLHEP/Random/RandFlat.h"
00019 
00020 using namespace std;
00021 
00022 
00023 FP420ClusterMain::FP420ClusterMain(const edm::ParameterSet& conf, int dn, int sn, int pn, int rn):conf_(conf),dn0(dn),sn0(sn),pn0(pn),rn0(rn)  { 
00024   
00025   verbosity         = conf_.getUntrackedParameter<int>("VerbosityLevel");
00026   ElectronPerADC_   = conf_.getParameter<double>("ElectronFP420PerAdc");
00027   clusterMode_      = conf_.getParameter<std::string>("ClusterModeFP420");
00028   ChannelThreshold  = conf_.getParameter<double>("ChannelFP420Threshold");//6
00029   SeedThreshold     = conf_.getParameter<double>("SeedFP420Threshold");//7
00030   ClusterThreshold  = conf_.getParameter<double>("ClusterFP420Threshold");//7
00031   MaxVoidsInCluster = conf_.getParameter<int>("MaxVoidsFP420InCluster");//1
00032   
00033   if (verbosity > 0) {
00034     std::cout << "FP420ClusterMain constructor: ElectronPerADC = " << ElectronPerADC_ << std::endl;
00035     std::cout << " clusterMode = " << clusterMode_ << std::endl;
00036     std::cout << " ChannelThreshold = " << ChannelThreshold << std::endl;
00037     std::cout << " SeedThreshold = " << SeedThreshold << std::endl;
00038     std::cout << " ClusterThreshold = " << ClusterThreshold << std::endl;
00039     std::cout << " MaxVoidsInCluster = " << MaxVoidsInCluster << std::endl;
00040   }
00041   xytype=2;// only X types of planes
00042   ENC_ = 960.;    // 
00043   Thick300 = 0.300;
00044   BadElectrodeProbability_ = 0.002;
00045   //UseNoiseBadElectrodeFlagFromDB_ = true;
00046   UseNoiseBadElectrodeFlagFromDB_ = false;
00047   //
00048   // pitches and ldriftes:
00049   //
00050   ldriftX = 0.050; 
00051   ldriftY = 0.050;// was 0.040
00052   pitchY= 0.050;// was 0.040
00053   pitchX= 0.050;
00054   moduleThicknessY = 0.250; // mm
00055   moduleThicknessX = 0.250; // mm
00056 
00057   //numStripsY = 200;        // Y plate number of strips:200*0.050=10mm (xytype=1)
00058   //numStripsX = 400;        // X plate number of strips:400*0.050=20mm (xytype=2)
00059   numStripsY = 144;        // Y plate number of strips:144*0.050=7.2mm (xytype=1)
00060   numStripsX = 160;        // X plate number of strips:160*0.050=8.0mm (xytype=2)
00061 
00062   //numStripsYW = 50;        // Y plate number of W strips:50 *0.400=20mm (xytype=1) - W have ortogonal projection
00063   //numStripsXW = 25;        // X plate number of W strips:25 *0.400=10mm (xytype=2) - W have ortogonal projection
00064   numStripsYW = 20;        // Y plate number of W strips:20 *0.400=8.0mm (xytype=1) - W have ortogonal projection
00065   numStripsXW = 18;        // X plate number of W strips:18 *0.400=7.2mm (xytype=2) - W have ortogonal projection
00066   
00067   //  sn0 = 4;
00068   //  pn0 = 9;
00069 
00070 
00071   theFP420NumberingScheme = new FP420NumberingScheme();
00072 
00073 
00074   if (verbosity > 1) {
00075     std::cout << "FP420ClusterMain constructor: sn0 = " << sn0 << " pn0=" << pn0 << " dn0=" << dn0 << " rn0=" << rn0 << std::endl;
00076     std::cout << "FP420ClusterMain constructor: ENC = " << ENC_ << std::endl;
00077     std::cout << " Thick300 = " << Thick300 << std::endl;
00078     std::cout << " BadElectrodeProbability = " << BadElectrodeProbability_ << std::endl;
00079     std::cout << " ldriftX = " << ldriftX << " ldriftY = " << ldriftY << std::endl;
00080     std::cout << " pitchY = " << pitchY << " pitchX = " << pitchX << std::endl;
00081     std::cout << " numStripsY = " << numStripsY << " numStripsX = " << numStripsX << std::endl;
00082     std::cout << " moduleThicknessY = " << moduleThicknessY << " moduleThicknessX = " << moduleThicknessX << std::endl;
00083   }
00084   
00085   if (UseNoiseBadElectrodeFlagFromDB_==false){    
00086     if (verbosity > 0) {
00087       std::cout << "using a SingleNoiseValue and good electrode flags" << std::endl;
00088     }
00089   } else {
00090     if (verbosity > 0) {
00091       std::cout << "using Noise and BadElectrode flags accessed from DB" << std::endl;
00092     }
00093   }
00094   
00095   if ( clusterMode_ == "ClusterProducerFP420" ) {
00096     
00097     
00098     //    ChannelThreshold    = 6.0;// was 2.6.0 7 18
00099     //   SeedThreshold       = 7.0;//was 3.7.0  8 20
00100     // ClusterThreshold    = 7.0;// was 2. 7.0 8 20
00101     // MaxVoidsInCluster   = 1; 
00102     threeThreshold_ = new ClusterProducerFP420(ChannelThreshold,
00103                                                SeedThreshold,
00104                                                ClusterThreshold,
00105                                                MaxVoidsInCluster);
00106     validClusterizer_ = true;
00107   } else {
00108     std::cout << "ERROR:FP420ClusterMain: No valid clusterizer selected" << std::endl;
00109     validClusterizer_ = false;
00110   }
00111 }
00112 
00113 FP420ClusterMain::~FP420ClusterMain() {
00114   if ( threeThreshold_ != 0 ) {
00115     delete threeThreshold_;
00116   }
00117 }
00118 
00119 
00120 //void FP420ClusterMain::run(const DigiCollectionFP420 *input, ClusterCollectionFP420 &soutput,
00121 //                         const std::vector<ClusterNoiseFP420>& electrodnoise)
00122 void FP420ClusterMain::run(edm::Handle<DigiCollectionFP420> &input, std::auto_ptr<ClusterCollectionFP420> &soutput,
00123                            std::vector<ClusterNoiseFP420>& electrodnoise)
00124 
00125 {
00126   // unpack from iu:
00127   //  int  sScale = 20, zScale=2;
00128   //  int  sector = (iu-1)/sScale + 1 ;
00129   //  int  zmodule = (iu - (sector - 1)*sScale - 1) /zScale + 1 ;
00130   //  int  zside = iu - (sector - 1)*sScale - (zmodule - 1)*zScale ;
00131   
00132     if (verbosity > 0) {
00133       std::cout << "FP420ClusterMain: OK1" << std::endl;
00134     }
00135   if ( validClusterizer_ ) {
00136     
00137     int number_detunits          = 0;
00138     int number_localelectroderechits = 0;
00139     
00140     // get vector of detunit ids
00141     //    const std::vector<unsigned int> detIDs = input->detIDs();
00142     
00143     // to be used in put (besause of 0 in cluster collection for: 1) 1st cluster and 2) case of no cluster)
00144     // ignore 0, but to save info for 1st cluster record it second time on place 1   .
00145     
00146     bool first = true;
00147     // loop over detunits
00148     for (int det=1; det<dn0; det++) {
00149       for (int sector=1; sector<sn0; sector++) {
00150         for (int zmodule=1; zmodule<pn0; zmodule++) {
00151           for (int zside=1; zside<rn0; zside++) {
00152             // intindex is a continues numbering of FP420
00153             unsigned int detID = theFP420NumberingScheme->FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
00154             if (verbosity > 0) {
00155               std::cout << " FP420ClusterMain:1 run loop   index no  iu = " << detID  << std::endl;
00156             }     
00157             // Y:
00158             if (xytype ==1) {
00159               numStrips = numStripsY*numStripsYW;  
00160               moduleThickness = moduleThicknessY; 
00161               pitch= pitchY;
00162               ldrift = ldriftX;
00163             }
00164             // X:
00165             if (xytype ==2) {
00166               numStrips = numStripsX*numStripsXW;  
00167               moduleThickness = moduleThicknessX; 
00168               pitch= pitchX;
00169               ldrift = ldriftY;
00170             }
00171             
00172             
00173             //    for ( std::vector<unsigned int>::const_iterator detunit_iterator = detIDs.begin(); detunit_iterator != detIDs.end(); ++detunit_iterator ) {
00174             //      unsigned int detID = *detunit_iterator;
00175             ++number_detunits;
00176             
00177             //   .
00178             //   GET DIGI collection  !!!!
00179             //   .
00180             //    const DigiCollectionFP420::Range digiRange = input->get(detID);
00181             DigiCollectionFP420::Range digiRange;
00182             std::vector<HDigiFP420> dcollector;
00183             // if (dcollector.size()>0){
00184             if (verbosity > 0) {
00185               std::cout << " FP420ClusterMain:2 number_detunits = " << number_detunits  << std::endl;
00186             }     
00187             digiRange = input->get(detID);
00188             //digiRange = input.get(detID);
00189             // }
00190             
00191             if (verbosity > 0) {
00192               std::cout << " FP420ClusterMain: input->get DONE dcollector.size()=" << dcollector.size() << std::endl;
00193             }     
00194             
00195             DigiCollectionFP420::ContainerIterator sort_begin = digiRange.first;
00196             DigiCollectionFP420::ContainerIterator sort_end = digiRange.second;
00197             for ( ;sort_begin != sort_end; ++sort_begin ) {
00198               dcollector.push_back(*sort_begin);
00199             } // for
00200             if (dcollector.size()>0) {
00201               
00202               DigiCollectionFP420::ContainerIterator digiRangeIteratorBegin = digiRange.first;
00203               DigiCollectionFP420::ContainerIterator digiRangeIteratorEnd   = digiRange.second;
00204               if (verbosity > 0) {
00205                 std::cout << " FP420ClusterMain: channel Begin = " << (digiRangeIteratorBegin)->channel()  << std::endl;
00206                 std::cout << " FP420ClusterMain: channel end = " << (digiRangeIteratorEnd-1)->channel()  << std::endl;
00207               }     
00208               if (verbosity > 0) {
00209                 std::cout << " FP420ClusterMain:3 noise treatment  " << std::endl;
00210               }   
00211               if ( clusterMode_ == "ClusterProducerFP420" ) {
00212                 
00213                 std::vector<ClusterFP420> collector;
00214                 //          std::vector<ClusterFP420> collector;
00215                 
00216                 if (UseNoiseBadElectrodeFlagFromDB_==false){      
00217                   
00218                   //Case of SingleValueNoise flags for all electrodes of a Detector
00219                   
00220                   
00221                   //float noise = ENC_*ldrift/Thick300/ElectronPerADC_;//Noise is proportional to charge collection path 
00222                   float noise = ENC_*moduleThickness/Thick300/ElectronPerADC_;//Noise is proportional to moduleThickness
00223                   
00224                   //vector<float> noiseVec(numElectrodes,noise);            
00225                   //Construct a ElectrodNoiseVector ( in order to be compliant with the DB access)
00226                   ElectrodNoiseVector vnoise;
00227                   ClusterNoiseFP420::ElectrodData theElectrodData;                 
00228                   
00229                   if (verbosity > 0) {
00230                     std::cout << " FP420ClusterMain:4 numStrips = " << numStrips  << std::endl;
00231                   }       
00232                   for(int electrode=0; electrode < numStrips; ++electrode){
00233                     //   discard  randomly  bad  electrode with probability BadElectrodeProbability_
00234                     bool badFlag= CLHEP::RandFlat::shoot(1.) < BadElectrodeProbability_ ? true : false;
00235                     theElectrodData.setData(noise,badFlag);
00236                     vnoise.push_back(theElectrodData);// fill vector vnoise
00237                   } // for
00238                   
00239                   if (verbosity > 0) {
00240                     std::cout << " FP420ClusterMain:5 BadElectrodeProbability added " << std::endl;
00241                   }       
00242                   //clusterizeDetUnit   or    clusterizeDetUnitPixels      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00243                   collector.clear();
00244                   //          std::vector<ClusterFP420> collector;
00245                   //  collector = threeThreshold_->clusterizeDetUnit(digiRangeIteratorBegin,digiRangeIteratorEnd,detID,vnoise);
00246                   //   if (dcollector.size()>0){
00247                   collector = threeThreshold_->clusterizeDetUnitPixels(digiRangeIteratorBegin,digiRangeIteratorEnd,detID,vnoise,xytype,verbosity);
00248                   //   }
00249                   if (verbosity > 0) {
00250                     std::cout << " FP420ClusterMain:6 threeThreshold OK " << std::endl;
00251                   }       
00252                   
00253                   
00254                 } else {
00255                   //Case of Noise and BadElectrode flags access from DB
00256                   /*
00257                     const ElectrodNoiseVector& vnoise = electrodnoise->getElectrodNoiseVector(detID);
00258                     
00259                     if (vnoise.size() <= 0) {
00260                     std::cout << "WARNING requested Noise Vector for detID " << detID << " that isn't in map " << std::endl; 
00261                     continue;
00262                     }
00263                     collector.clear();
00264                     collector = threeThreshold_->clusterizeDetUnit(digiRangeIteratorBegin,digiRangeIteratorEnd,detID,vnoise);
00265                   */
00266                   
00267                   
00268                 }// if (UseNoiseBadElectrodeFlagFromDB
00269                 
00270                 if (collector.size()>0){
00271                   ClusterCollectionFP420::Range inputRange;
00272                   inputRange.first = collector.begin();
00273                   inputRange.second = collector.end();
00274                   
00275                   if (verbosity > 0) {
00276                     std::cout << " FP420ClusterMain:7 collector.size()>0 " << std::endl;
00277                   }       
00278                   if ( first ) {
00279                     // use it only if ClusterCollectionFP420 is the ClusterCollection of one event, otherwise, do not use (loose 1st cl. of 1st event only)
00280                     first = false;
00281                     unsigned int detID0 = 0;
00282                     if (verbosity > 0) {
00283                       std::cout << " FP420ClusterMain:8 first soutput->put " << std::endl;
00284                     }     
00285                     soutput->put(inputRange,detID0); // !!! put into adress 0 for detID which will not be used never
00286                   } //if ( first ) 
00287                   
00288                   // !!! put
00289                   if (verbosity > 0) {
00290                     std::cout << " FP420ClusterMain:9 soutput->put " << std::endl;
00291                   }       
00292                   soutput->put(inputRange,detID);
00293                   
00294                   number_localelectroderechits += collector.size();
00295                 } // if (collector.size
00296               }// if ( clusterMode
00297               if (verbosity > 0) {
00298                 std::cout << "[FP420ClusterMain] execution in mode " << clusterMode_ << " generating " << number_localelectroderechits << " ClusterFP420s in " << number_detunits << " DetUnits." << std::endl; 
00299               }//if (verb
00300             }// if (dcollector.siz
00301           }//for
00302         }//for
00303       }//for
00304     }//for
00305     
00306     if (verbosity == -50 ) {
00307 
00308       //     check of access to the collector:
00309       for (int det=1; det<dn0; det++) {
00310         for (int sector=1; sector<sn0; sector++) {
00311           for (int zmodule=1; zmodule<pn0; zmodule++) {
00312             for (int zside=1; zside<rn0; zside++) {
00313               // intindex is a continues numbering of FP420
00314               unsigned int iu = theFP420NumberingScheme->FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
00315                 std::cout <<" iu = " << iu <<" sector = " << sector <<" zmodule = " << zmodule <<" zside = " << zside << "  det=" << det << std::endl;
00316               std::vector<ClusterFP420> collector;
00317               collector.clear();
00318               ClusterCollectionFP420::Range outputRange;
00319               outputRange = soutput->get(iu);
00320               // fill output in collector vector (for may be sorting? or other checks)
00321               ClusterCollectionFP420::ContainerIterator sort_begin = outputRange.first;
00322               ClusterCollectionFP420::ContainerIterator sort_end = outputRange.second;
00323               for ( ;sort_begin != sort_end; ++sort_begin ) {
00324                 collector.push_back(*sort_begin);
00325               } // for
00326               std::cout <<" ===" << std::endl;
00327               std::cout <<" ===" << std::endl;
00328               std::cout <<" =========== FP420ClusterMain:check: iu= " << iu <<    " zside = " << zside << std::endl;
00329               std::cout <<"  ======renew collector size = " << collector.size() << std::endl;
00330               std::cout <<" ===" << std::endl;
00331               std::cout <<" ===" << std::endl;
00332               std::vector<ClusterFP420>::const_iterator simHitIter = collector.begin();
00333               std::vector<ClusterFP420>::const_iterator simHitIterEnd = collector.end();
00334               // loop in #clusters
00335               for (;simHitIter != simHitIterEnd; ++simHitIter) {
00336                 const ClusterFP420 icluster = *simHitIter;
00337                 //   if(icluster.amplitudes().size()>390) {
00338                 std::cout << " ===== size of cluster= " << icluster.amplitudes().size() << std::endl;
00339                 std::cout <<" ===" << std::endl;
00340                 std::cout << " ===== firstStrip = " << icluster.firstStrip() << "  barycenter = " << icluster.barycenter() << "  barycenterW = " << icluster.barycenterW() << std::endl;
00341                 std::cout <<" ===" << std::endl;
00342                 for(unsigned int i = 0; i < icluster.amplitudes().size(); i++ ) {
00343                   std::cout <<  "i = " << i << "   amplitudes = "  << icluster.amplitudes()[i] << std::endl;
00344                 }// for ampl
00345                 std::cout <<" ===" << std::endl;
00346                 std::cout <<" ===" << std::endl;
00347                 std::cout <<" =======================" << std::endl;
00348                 //  }// if(icluster.amplitudes().size()>390
00349               }//for cl
00350               
00351               /* 
00352                  for (DigitalMapType::const_iterator i=collector.begin(); i!=collector.end(); i++) {
00353                  std::cout << "DigitizerFP420:check: HDigiFP420::  " << std::endl;
00354                  std::cout << " strip number is as (*i).first  = " << (*i).first << "  adc is in (*i).second  = " << (*i).second << std::endl;
00355                  }
00356               */
00357               
00358               //==================================
00359               
00360             }   // for
00361           }   // for
00362         }   // for
00363       }   // for
00364       
00365       //     end of check of access to the strip collection
00366       std::cout <<"=======            FP420ClusterMain:                    end of check     " << std::endl;
00367       
00368     }// if (verbosit
00369     
00370     
00371     
00372   }// if ( validClusterizer_
00373 }